insertAt
🎯 Inserts items at the given index into the array.
Syntax
TypeScript
import { insertAt } from '@opentf/std'; insertAt<T>(arr: T[], index: number, options?: { items: T[] }): T[]
Parameters
| Name | Type | Description |
|---|---|---|
| arr | T[] | The source array. |
| index | number | The index to insert items at. |
| options | { items: T[] } | The items to insert. |
Returns
A new array with the inserted items.
Examples
TypeScript
insertAt([1, 2, 3], 1, { items: [5] }) //=> [1, 5, 2, 3] insertAt([1, 2, 3], 0, { items: [5, 6] }) //=> [5, 6, 1, 2, 3] insertAt([1, 2, 3], 3, { items: [4] }) //=> [1, 2, 3, 4]