pullAllBy()
pullAllBy<
T>(array,values,iteratee):T[]
Removes all given values from array using an iteratee for equality comparisons.
Use differenceBy instead for immutable operations.
Reason:
Pithos design philosophy always favors immutability.
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โ
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โ
| Array | Values | Iteratee | Result |
|---|---|---|---|
[{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"]
Deprecated: Use