Array.findLastIndex method
Array › findLastIndex
Official
Returns the index of the last element that satisfies the provided predicate.Signature:
findLastIndex(predicate: (value: T) => boolean): numberParameters:
| Parameter | Type | Description |
|---|---|---|
| predicate | (value: T) => boolean | The predicate to test each element. |
Returns: number — The index of the last element that satisfies the predicate, or -1 if no such element is found.
Since: 1.4.4
Example:
console.log([1, 2, 3, 2, 1].findLastIndex(x => x === 2)); // 3console.log([1, 2, 3, 2, 1].findLastIndex(x => x === 4)); // -1