Skip to content

atOr

ts
function Array.atOr<T, U>(
    target: readonly T[],
    offset: number,
    or: U,
): Exclude<T, null | undefined> | U

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

Example

ts
import { Array } from "@monstermann/array";

Array.atOr([1, null], -1, 2); // 2
ts
import { Array } from "@monstermann/array";

pipe([1, null], Array.atOr(-1, 2)); // 2