find
find() function
Looks through each value in Iterable/AsyncIterable, returning the first one that passes a truth test f
, or undefined
if no value passes the test.
Signature:
declare function find<T>(f: (a: T) => unknown, iterable: Iterable<T>): T | undefined;
Returns:
T | undefined
Example
find((a) => a === 2, [1, 2, 3, 4]); // 2
find((a) => a === "r", "marpple"); // 'r'