Function find

Finds the first element in the source array that satisfies the provided predicate function.

Returns undefined if no element satisfies the predicate.

const findPositive = find((x: number) => x > 0);
const a = findPositive([1, 2, 3]); // 1
const b = findPositive([-1, 0, -2]); // undefined
  • Type Parameters

    • Item

    Parameters

    • predicate: (item: Item) => boolean

    Returns (source: readonly Item[]) => undefined | Item