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.