Array
arrIns

Inserts items at the given index into the given array.

Immutable: This does not mutate the given array.

Syntax

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

Examples

arrIns([]) //=> []
 
arrIns([1]) //=> [1]
 
arrIns([1], 0) //=> [1]
 
arrIns([1], 0, 0) //=> [0, 1]
 
arrIns([1], 1, 0) //=> [1, 0]
 
arrIns([1, 2, 3], 1, 5) //=> [1, 5, 2, 3]
 
arrIns([1, 2, 3], -1, 5) //=> [1, 2, 5, 3]
 
arrIns([1, 2, 3], -3, 5) //=> [5, 1, 2, 3]
 
arrIns([1, 2, 3], 3, 5) //=> [1, 2, 3, 5]
 
arrIns([1, 2, 3], 3, 5, 6) //=> [1, 2, 3, 5, 6]
 
arrIns([1, 2, 3], null, 5, 6) //=> [1, 2, 3, 5, 6]
 
arrIns([1, 2, 3], 0, [5, 6]) //=> [[5, 6], 1, 2, 3]
 
arrIns([1, 2, 3], 0, ...[5, 6]) //=> [5, 6, 1, 2, 3]
 

Try