the Iterable value type
the Predicate to match
Find the first matching element of an Iterable, or a default value if the Iterable is empty.
Returns undefined if the Iterable is empty and no defaultValue
was provided.
Get the first matching element
const findFirstEven = findFirst(isEven);
const result = findFirstEven([1,2,3]);
console.log(result); // 2
Get the first matching element or the defaultValue
const findFirstEven = findFirst(isEven, 2);
const result = findFirstEven([1]);
console.log(result); // 2
filter and first for similar operations.
the first matching element of the Iterable, or the given defaultValue
the Iterable value type
the Predicate to match
Generated using TypeDoc
Find the first matching element of an Iterable, or a default value if the Iterable is empty.
Returns
undefinedif the Iterable is empty and nodefaultValuewas provided.Example
Get the first matching element
Example
Get the first matching element or the
defaultValueSee
filter and first for similar operations.
Returns
the first matching element of the Iterable, or the given
defaultValue