Skip to content

atOrElse

atOrElse(array, offset, fallback)

Returns the value at the specified offset. Calls fallback if the offset was out of range, or the retrieved value was nullable.

ts
atOrElse([1, null], -1, (array) => array.length); // 2
ts
pipe(
    [1, null],
    atOrElse(-1, (array) => array.length),
); // 2