Find the first value in an iterable which matches a predicate.
The first matching value, or undefined if no matching value is found.
undefined
Linear.
import { find } 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' }];find(data, isCat).name; // 'fluffy'
The iterable object to search.
The predicate function to apply to the values.
Generated using TypeDoc
Find the first value in an iterable which matches a predicate.
Returns
The first matching value, or
undefinedif no matching value is found.Complexity
Linear.
Example