apiref
bsearch@1.0.0

firstElementAsync()  Function

Returns the first element in array whose value satisfies the predicate.

Signature

export declare function firstElementAsync<T>(array: readonly T[], predicate: (value: T, index: number, array: readonly T[]) => PromiseLike<boolean>): Promise<T | undefined>;

Parameters

ParameterTypeDescription
arrayreadonly T[]

The array to search.

predicate(value: T, index: number, array: readonly T[]) => PromiseLike<boolean>

A predicate. There should exist some index I such that predicate(array[i]) returns true for all i >= I and returns false otherwise.

(Returns)Promise<T | undefined>

A promise that resolves to the first element in array whose value satisfies the predicate, or undefined if no such element exists.