Skip to content

without

Returns a new array with all occurrences of the given values removed.

Unlike difference, which operates on two arrays as set operands, without uses a variadic API suited for removing known sentinel values inline. Uses SameValueZero equality (same as Array.prototype.includes). null and undefined are treated as empty arrays and return [].

Available since v2.0.0

import { without } from '@helpers4/array';
without<T>(array: readonly T[] | null | undefined, values: T[]): T[]
ParameterTypeDescription
arrayreadonly T[] | null | undefinedThe source array.
valuesT[]One or more values to exclude from the result.

T[] — A new array without the specified values.

Returns a new array with all occurrences of the given value removed.

without([1, 2, 3, 2, 4], 2)
// => [1, 3, 4]

All listed values are excluded from the result.

without([1, 2, 3, 2, 4], 2, 3)
// => [1, 4]

View source on GitHub