Skip to content

findIndex() function

Returns the index of the first element of Iterable/AsyncIterable which matches f, or -1 if no element matches.

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.