Skip to content

find() function

Iterable/AsyncIterable の各値を調べ、真偽テスト f をパスする最初の値を返します。テストをパスする値がない場合は undefined を返します。

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.