Skip to content

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:

typescript
declare function find<T>(f: (a: T) => unknown, iterable: Iterable<T>): T | undefined;

Example

ts
find((a) => a === 2, [1, 2, 3, 4]); // 2

find((a) => a === "r", "marpple"); // 'r'

Try It

Open Source Code

Released under the Apache-2.0 License.