findLastIndex
arrayThis method is like findIndex except that it iterates over elements of collection from right to left.
Signature
findLastIndex<T>(array: T[], predicate: (value: T) => boolean, fromIndex?: number): numberParameters
| Name | Type | Description |
|---|---|---|
array | T[] | The array to inspect |
predicate | (value: T) => boolean | The function invoked per iteration |
fromIndex? | number | The index to search from |
Returns
number - Returns the index of the found element, else -1
Examples
Find from right
import { findLastIndex } from 'dashlite'
const users = [
{ user: 'barney', active: true },
{ user: 'fred', active: false },
{ user: 'pebbles', active: false }
]
const result = findLastIndex(users, (o) => o.user === 'pebbles')
console.log(result)Output:
2Available since version 1.0.0