JavaScript Array findLastIndex()Method
Examples
Find the last element with a value greater than 18:
const ages = [3, 10, 18, 20];
ages.findLastIndex(checkAge);
function checkAge(age) {
return age > 18;
}
Output:
Google,JYSHARE,Example,Taobao
Try it Yourself »
Definition and Usage
The findLastIndex() method executes a function for each array element.
The findLastIndex() method returns the index (position) of the last element that passes the test.
If no match is found, it returns -1.
The findLastIndex() method does not execute the function for empty array elements.
The findLastIndex() method does not change the original array.
Array Search Methods:
| Method | Description |
|---|---|
indexOf() | Find the index of the first element with a specified value |
lastIndexOf() | Find the index of the last element with a specified value |
find() | Find the value of the first element that passes the test |
findIndex() | Find the index of the first element that passes the test |
findLast() | Find the value of the last element that passes the test |
findLastIndex() | Find the index of the last element that passes the test |
Browser Support
findLastIndex() is an ES2023 feature, supported by all modern browsers since July 2023.
| Chrome 110 | Edge 110 | Firefox 115 | Safari 16.4 | Opera 96 |
| Feb 2023 | Feb 2023 | Jul 2023 | Mar 2023 | May 2023 |
Syntax
array.findLastIndex(function(currentValue, index, arr), thisValue)
Parameters
| Parameter | Description |
|---|---|
| function | Required. The function to run for each array element. |
| currentValue | Required. The value of the current element. |
| index | Optional. The index of the current element. |
| arr | Optional. The array of the current element. |
| thisValue | Optional, defaults to undefined. A value passed as the function's this value. |
Return Value
| Type | Description |
|---|---|
| Numbe | The index of the last element that passes the test; otherwise -1. |
Other Extensions
JavaScript Array Object