Creates a function that returns the index of the first element in an iterable that satisfies the predicate. Similar to Array.prototype.findIndex(), but works with any iterable.
Type of elements in the iterable
Function to test each element and its index
A function that takes an iterable and returns the index of the first matching element, or -1 if no match is found
// Find index of first even numberconst firstEvenIndex = findIndex((n: number) => n % 2 === 0)([1, 3, 5, 6, 7, 8])// Result: 3 Copy
// Find index of first even numberconst firstEvenIndex = findIndex((n: number) => n % 2 === 0)([1, 3, 5, 6, 7, 8])// Result: 3
// Find index of first element greater than 10const greaterThan10Index = findIndex((n: number) => n > 10)([1, 5, 8, 12, 15])// Result: 3 Copy
// Find index of first element greater than 10const greaterThan10Index = findIndex((n: number) => n > 10)([1, 5, 8, 12, 15])// Result: 3
// No match returns -1const negativeIndex = findIndex((n: number) => n < 0)([1, 2, 3, 4])// Result: -1 Copy
// No match returns -1const negativeIndex = findIndex((n: number) => n < 0)([1, 2, 3, 4])// Result: -1
Creates a function that returns the index of the first element in an iterable that satisfies the predicate. Similar to Array.prototype.findIndex(), but works with any iterable.