JavaScript Array.prototype.findIndex() Method
The findIndex() method returns the index of the first element that passes a test, or -1 if no element does.
Description
The findIndex() method returns the index of the first element for which the callback returns a truthy value, or -1 if there is none. It is useful when you need to update or remove the element, for example with splice() or with().
Unlike indexOf(), which looks for an exact value, findIndex() takes a test function, so it can match objects by their properties.
Unlike most array methods, findIndex() calls the callback for empty slots in sparse arrays too, passing undefined. A common pattern is updating an item in place: find its index, then assign arr[i] = newItem, or use arr.with(i, newItem) for a copy. Always check for -1 first, because arr[-1] is just undefined and splice(-1, 1) would remove the last element.
Syntax
array.findIndex(callbackFn)
array.findIndex(callbackFn, thisArg)Parameters
- callbackFnA function called for each element, receiving
element,indexandarray. - thisArgOptional. A value to use as
thisinsidecallbackFn.
Return Value
The index of the first element that passes the test, or -1 if none does.
Example
Browser Support
The following information will show you the current browser support for the Array.prototype.findIndex() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





