findIndex()

ES6+

Returns the index of the first element in the array that satisfies the provided testing function.

Syntax

array.findIndex(callback(element, index, array), thisArg)

Parameters

callback Function

Function to test each element

Return Value

number

The index of the first matching element, or -1

Examples

JavaScript
const numbers = [5, 12, 8, 130, 44];
const index = numbers.findIndex(x => x > 10);
console.log(index);
Output:
// 1

Related Methods