Array
arrReplace

Replaces items at the given index from the given array.

Immutable: This does not mutate the given array.

Syntax

import { arrReplace } from '@opentf/std';
 
arrReplace<T>(
  arr: T[] = [],
  index: number | null,
  deleteCount: number | null,
  ...replacements: T[]
)

Examples

arrReplace([]) // => []
 
arrReplace([1]) // => [1]
 
arrReplace([1, 2, 3], 0, 1, 'a') // => ['a', 2, 3]
 
arrReplace([1, 2, 3], null, 1, 'a') // => [1, 2, 'a']
 
arrReplace([1, 2, 3], 3, null, 'c') // => [1, 2, 3, 'c']
 
const months = ['Jan', 'Feb', 'Apr', 'May'];
arrReplace(months, 1, 1, 'Feb', 'Mar') //=> ['Jan', 'Feb', 'Mar', 'Apr', 'May']
 
arrReplace(months, 1, null, 'Feb', 'Mar') //=> ['Jan', 'Feb', 'Mar', 'May']

Try