Skip to content

findIndex() function

返回 Iterable/AsyncIterable 中匹配 f 的第一个元素的索引,如果没有元素匹配则返回 -1。

Signature:

typescript
declare function findIndex<T extends readonly []>(f: Arrow, iterable: T): -1;

Example

ts
const arr = [{ a: 1 }, { a: 2 }, { a: 3 }];
findIndex((obj) => obj.a === 1, arr); // 0
findIndex((obj) => obj.a === 2, arr); // 1
findIndex((obj) => obj.a === 4, arr); // -1

Open Source Code

Released under the Apache-2.0 License.