Skip to content

pull

Removes all specified values from an array.

This function changes arr in place. If you want to remove values without modifying the original array, use difference.

Signature

typescript
function pull<T>(arr: T[], valuesToRemove: unknown[]): T[];

Parameters

  • arr (T[]): The array to modify.
  • valuesToRemove (unknown[]): The values to remove from the array.

Returns

(T[]): The modified array with the specified values removed.

Examples

typescript
const numbers = [1, 2, 3, 4, 5, 2, 4];
pull(numbers, [2, 4]);
console.log(numbers); // [1, 3, 5]

Released under the MIT License.