JavaScript Array.prototype.findLastIndex() Method
The findLastIndex() method returns the index of the last element in an array that passes a test, or -1.
Description
The findLastIndex() method searches the array from the end and returns the index of the last element for which the callback returns a truthy value. If there is no match it returns -1. It's the backwards counterpart of findIndex().
The index it returns is the position counted from the start of the array, not from the end, so it can be used directly with bracket access, splice() or with(). Like findIndex(), it calls the callback for empty slots as well as filled ones, passing undefined for them.
A typical use is finding the most recent entry in a history list that meets a condition, or the last valid item before an error, without reversing the array. When you're searching for an exact value rather than testing a condition, lastIndexOf() does the same job.
Syntax
array.findLastIndex(callbackFn)
array.findLastIndex(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 last 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.findLastIndex() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





