Skip to main content

pullAll()

pullAll<T>(array, values): T[]

Creates an array excluding all specified values.

DEPRECATED

Use difference from Arkhe instead.

Reason:
Pithos design philosophy always favors immutability.

note

Mutates the array in place.


Type Parametersโ€‹

T: Tโ€‹

The type of elements in the array.


Parametersโ€‹

array: T[]โ€‹

The array to modify.

values: T[]โ€‹

The values to exclude.


Returns: T[]โ€‹

The mutated array.


See Alsoโ€‹

difference


Sinceโ€‹

2.0.0


Also known asโ€‹

difference (Remeda, Effect) ยท pullAll (Lodash, es-toolkit) ยท โŒ (Radashi, Ramda, Modern Dash, Antfu)


Exampleโ€‹

const numbers = [1, 2, 3, 4, 2];
pullAll(numbers, [2, 3]);
console.log(numbers); // [1, 4]

How it works?โ€‹

Removes all specified values from array in place (mutates).

Mutation Flowโ€‹

Common Inputsโ€‹

ArrayValuesResult
[1, 2, 3, 4, 2][2, 3][1, 4]
['a', 'b', 'c']['b']['a', 'c']

warning Deprecated: Use difference() from Arkhe for immutable operations.


Use Casesโ€‹

Remove multiple values ๐Ÿ“Œโ€‹

Remove all occurrences of specified values from array.

const items = [1, 2, 3, 2, 4, 2];
const toRemove = [2, 3];
const result = items.filter(x => !toRemove.includes(x));
// [1, 4]

Clean array dataโ€‹

Filter out unwanted values from dataset.

const tags = ['js', 'deprecated', 'ts', 'legacy'];
const blacklist = ['deprecated', 'legacy'];
const clean = tags.filter(t => !blacklist.includes(t));
// ['js', 'ts']