Skip to content

removeAtOr ​

ts
function Array.removeAtOr<T, U>(
    target: readonly T[],
    idx: number,
    or: U,
): T[] | U

Removes the element at index idx from target array. Supports negative indices to count from the end. If the index is out of bounds, returns the fallback value or.

Example ​

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

Array.removeAtOr([1, 2, 3], 1, []); // [1, 3]
Array.removeAtOr([1, 2, 3], 5, []); // []
ts
import { Array } from "@monstermann/array";

pipe([1, 2, 3], Array.removeAtOr(1, [])); // [1, 3]
pipe([1, 2, 3], Array.removeAtOr(5, [])); // []