🎯 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
| Name | Type | Description |
|---|---|---|
| arr | T[] | The source array. |
| index | number | The index to replace items at. |
| items | T[] | 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]