replaceAt

🎯 Replaces items at the given index in the array.

Syntax

TypeScript
import { replaceAt } from '@opentf/std';
replaceAt<T>(arr: T[], index: number, options?: { items: T[] }): T[]

Parameters

NameTypeDescription
arrT[]The source array.
indexnumberThe index to replace items at.
options{ items: T[] }The items to replace with.

Returns

A new array with the replaced items.

Examples

TypeScript
replaceAt([1, 2, 3], 1, { items: [5] }) //=> [1, 5, 3]

replaceAt([1, 2, 3], 1, { items: [5, 6] }) //=> [1, 5, 6, 3]

replaceAt([1, 2, 3], 0, { items: [0] }) //=> [0, 2, 3]

Try it

Last updated on
Edit this page