Function: find()
ts
function find<T>(collection, predicate): T extends readonly U[] ? U : T[keyof T] | undefined;Finds the first matching value in an array or object. 在数组或对象中查找第一个匹配的值。
Type Parameters
| Type Parameter | Description |
|---|---|
T extends Record<string, unknown> | readonly unknown[] | The source collection type / 源集合类型 |
Parameters
| Parameter | Type | Description |
|---|---|---|
collection | T | The source collection / 源集合 |
predicate | (value, key, collection) => boolean | The match predicate / 匹配断言 |
Returns
T extends readonly U[] ? U : T[keyof T] | undefined
The first matching value, or undefined / 第一个匹配的值,或 undefined
Example
ts
find({ a: 1, b: 2 }, (value) => value > 1)
// => 2Since
1.2.0