R
fn

insert

v0.0.10tested

Return a new array with `items` inserted at `index`. The index is clamped into `[0, length]`, so a too-large index appends. Never mutates.

Example

ts
insert(['a', 'c'], 1, 'b'); // ['a', 'b', 'c']
insert(['a'], 99, 'b', 'c'); // ['a', 'b', 'c']

Signature

ts
export function insert<T>(array: readonly T[], index: number, ...items: T[]): T[]{ ... }

Type Parameters

T

Parameters

ParameterTypeDescription
arrayreadonly T[]The source array
indexnumberPosition to insert at
items?T[]Items to insert

Returns

T[]A new array with the items inserted