Skip to content

insertAt

insertAt<A>(index, item): (data) => readonly A[]

Defined in: Utils/Arr.ts:545

Returns a new array with item inserted before the element at index. Negative indices are clamped to 0; indices beyond the array length append to the end.

A

number

A

(data): readonly A[]

readonly A[]

readonly A[]

pipe([1, 2, 3], Arr.insertAt(1, 99)); // [1, 99, 2, 3]
pipe([1, 2, 3], Arr.insertAt(0, 99)); // [99, 1, 2, 3]
pipe([1, 2, 3], Arr.insertAt(3, 99)); // [1, 2, 3, 99]