Category
Remove all elements equal to a given element from an array. Strict equality (===) is used to compare elements.
===
Time complexity: O(n)
Space complexity: O(n)
The array to remove elements from
The element to remove
The return value of Array.prototype.splice
Array.prototype.splice
Array
const array = [1, 1, 2, 2, 3, 3];pullAll(array, 2); // [2, 2]console.log(array); // [1, 1, 3, 3]pullAll(array, 2); // []console.log(array); // [1, 1, 3, 3] Copy
const array = [1, 1, 2, 2, 3, 3];pullAll(array, 2); // [2, 2]console.log(array); // [1, 1, 3, 3]pullAll(array, 2); // []console.log(array); // [1, 1, 3, 3]
Remove all elements equal to a given element from an array. Strict equality (
===
) is used to compare elements.Time complexity: O(n)
Space complexity: O(n)