Skip to content

reject

The reject function returns a new array with elements that do not satisfy the provided test function.

Syntax

typescript
reject<T>(array: T[], fn: (value: T, index?: number, array?: T[]) => boolean): T[];

Parameters

NameTypeDescription
arrayT[]Source array
fn(value: T, index: number, array: T[]) => booleanPredicate function

Returns

TypeDescription
T[]New array with elements that fail predicate

Examples

typescript
reject([1, 2, 3, 4], x => x % 2 === 0); // => [1, 3]
reject(['a', 'b', 'c'], x => x === 'b'); // => ['a', 'c']

Notes

  • Useful for filtering unwanted elements.
  • Does not modify the original array.

References

Released under the MIT License.