pull()
pull<
T>(array, ...values):T[]
Removes all given values from array using SameValueZero for equality comparisons.
DEPRECATED
Use difference 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 remove.
Returns: T[]โ
The mutated array.
Sinceโ
2.0.0
Also known asโ
pull (Lodash, es-toolkit) ยท remove (Antfu) ยท without (Remeda) ยท โ (Radashi, Ramda, Effect, Modern Dash)
Exampleโ
const array = [1, 2, 3, 1, 2, 3];
pull(array, 2, 3);
console.log(array); // [1, 1]
How it works?โ
Removes all given values from an array (mutates).
Deprecated: Use immutable filter() or without() instead.
Native Equivalentโ
// โ pull(arr, ...values) // mutates
// โ
arr.filter(x => !values.includes(x)) // immutable
Use Casesโ
Remove values in place ๐โ
Remove specific values from an array (mutating).
const items = [1, 2, 3, 4, 5];
const toRemove = new Set([2, 4]);
const result = items.filter(x => !toRemove.has(x));
// => [1, 3, 5]
Remove single valueโ
Filter out a specific value.
const tags = ["js", "ts", "css", "js"];
tags.filter(t => t !== "js");
// => ["ts", "css"]
Remove multiple valuesโ
Exclude multiple values using a Set.
const nums = [1, 2, 3, 2, 4, 2, 5];
const exclude = new Set([2, 4]);
nums.filter(n => !exclude.has(n));
// => [1, 3, 5]