🎯 Inserts items at the given index into the array.

Syntax

TypeScript
import { insertAt } from '@opentf/std';

insertAt<T>(arr: T[], index: number, ...items: T[]): T[]

Parameters

NameTypeDescription
arrT[]The source array.
indexnumberThe index to insert items at.
itemsT[]The items to insert.

Returns

A new array with the inserted items.

Examples

TypeScript
insertAt([1, 2, 3], 1, 5) //=> [1, 5, 2, 3]

insertAt([1, 2, 3], 0, 5, 6) //=> [5, 6, 1, 2, 3]

insertAt([1, 2, 3], 3, 4) //=> [1, 2, 3, 4]
Last updated on
Edit this page