Function: findKey()
ts
function findKey<T>(object, predicate): keyof T | undefined;Finds the first key whose value matches a predicate. 查找第一个满足断言条件的键。
Type Parameters
| Type Parameter | Description |
|---|---|
T extends Record<string, unknown> | The source object type / 源对象类型 |
Parameters
| Parameter | Type | Description |
|---|---|---|
object | T | The source object / 源对象 |
predicate | (value, key) => boolean | The match predicate / 匹配断言 |
Returns
keyof T | undefined
The first matching key, or undefined / 第一个匹配的键,或 undefined
Example
ts
findKey({ a: 1, b: 2 }, (value) => value > 1)
// => 'b'Since
1.2.0