fn
insert
v0.0.10testedReturn 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
TParameters
| Parameter | Type | Description |
|---|---|---|
array | readonly T[] | The source array |
index | number | Position to insert at |
items? | T[] | Items to insert |
Returns
T[]A new array with the items inserted