Array.prototype.findIndex()

Returns the index of the first element that satisfies the testing function.

Since ES2015 Spec ↗

Syntax

arr.findIndex(callback, thisArg)

Parameters

NameTypeRequiredDescription
callback Function Yes Predicate called with (element, index, array). Return truthy to select the element.
thisArg any No Value to use as `this` when executing the callback.

Returns

number — The index of the first matching element, or -1 if none match.

Examples

const nums = [5, 12, 8, 130, 44];
console.log(nums.findIndex(n => n > 10));
Output
1
console.log([1, 2, 3].findIndex(n => n > 9));
Output
-1

Notes

Returns -1 when nothing matches. Use `find` to get the value instead of the index, or `indexOf` for a strict equality search.

Browser & runtime support

EnvironmentSince version
chrome 45
firefox 25
safari 8.0
edge 12
node 4.0

See also