Skip to main content

find

Iterates over elements of collection, returning the first element predicate returns truthy for. The predicate is invoked with three arguments: (value, index|key, collection).

API

function find<T>(
arr: T[],
predicate: (value: T, index: number, obj: T[]) => unknown
): T | undefined;

Usage

import { find } from "@feedzai/js-utilities";

const users = [
{ user: 'barney', age: 36, active: true },
{ user: 'fred', age: 40, active: false },
{ user: 'pebbles', age: 1, active: true },
]

find(users, items => items.age < 40)
// => { user: "barney", age: 36, active: true }