Aller au contenu principal

pullAllBy()

pullAllBy<T>(array, values, iteratee): T[]

Removes all given values from array using an iteratee for equality comparisons.

DEPRECATED

Use differenceBy instead for immutable operations.

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: readonly T[]

The values to remove.

iteratee: (item) => unknown | keyof T

A function or property key to compute the comparison value.


Returns: T[]

The mutated array.


See Also

differenceBy


Since

2.0.0


Also known as

pullAllBy (Lodash, es-toolkit) · ❌ (Remeda, Radashi, Ramda, Effect, Modern Dash, Antfu)


Example

// ❌ Deprecated approach (mutates array)
const array = [{ x: 1 }, { x: 2 }, { x: 3 }];
pullAllBy(array, [{ x: 1 }, { x: 3 }], 'x');
console.log(array); // [{ x: 2 }]

// ✅ Recommended approach (immutable)
const array = [{ x: 1 }, { x: 2 }, { x: 3 }];
const result = differenceBy(array, [{ x: 1 }, { x: 3 }], 'x');
console.log(result); // [{ x: 2 }]
console.log(array); // [{ x: 1 }, { x: 2 }, { x: 3 }] (unchanged)

How it works?

Removes values from array using an iteratee for comparison (mutates).

Mutation Flow

Common Inputs

ArrayValuesIterateeResult
[{x:1}, {x:2}][{x:1}]'x'[{x:2}]
[1.2, 2.3, 3.4][2.1]Math.floor[1.2, 3.4]

Deprecated: Use differenceBy() from Arkhe for immutable operations.


Use Cases

Remove by property 📌

Remove objects matching a property value.

const users = [{ id: 1 }, { id: 2 }, { id: 3 }];
const toRemove = new Set([1, 3]);
users.filter(u => !toRemove.has(u.id));
// => [{ id: 2 }]

Remove with custom comparator

Remove using a custom comparison function.

const items = [{ x: 1 }, { x: 2 }, { x: 3 }];
const exclude = [{ x: 2 }];
items.filter(a => !exclude.some(b => a.x === b.x));
// => [{ x: 1 }, { x: 3 }]

Filter by transformed value

Exclude items based on a derived value.

const words = ["hello", "WORLD", "foo"];
const excludeLower = new Set(["hello", "foo"]);
words.filter(w => !excludeLower.has(w.toLowerCase()));
// => ["WORLD"]