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]