🎯 Replaces items at the given index in the array.

Syntax

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

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

Parameters

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

Returns

A new array with the replaced items.

Examples

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

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

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