Find the index of the first value which matches a predicate.
The index of the first matching value, or -1 if no matching value is found.
-1
Linear.
import { findIndex } from '@lumino/algorithm';interface IAnimal { species: string, name: string };function isCat(value: IAnimal): boolean { return value.species === 'cat';}let data: IAnimal[] = [ { species: 'dog', name: 'spot' }, { species: 'cat', name: 'fluffy' }, { species: 'alligator', name: 'pocho' }];findIndex(data, isCat); // 1
The iterable object to search.
The predicate function to apply to the values.
Generated using TypeDoc
Find the index of the first value which matches a predicate.
Returns
The index of the first matching value, or
-1if no matching value is found.Complexity
Linear.
Example