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