Finds the index of the first element in the source array that satisfies the provided predicate function.
Returns -1 if no element satisfies the predicate.
-1
const findPositiveIndex = findIndex((x: number) => x > 0);const a = findPositiveIndex([1, 2, 3]); // 0const b = findPositiveIndex([-1, 0, -2]); // -1 Copy
const findPositiveIndex = findIndex((x: number) => x > 0);const a = findPositiveIndex([1, 2, 3]); // 0const b = findPositiveIndex([-1, 0, -2]); // -1
Finds the index of the first element in the source array that satisfies the provided predicate function.
Returns
-1
if no element satisfies the predicate.Example