Aller au contenu principal

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.

remarque

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']

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']