Function insert

  • Insert a value into an array at a specific index.

    Type Parameters

    • T

    Parameters

    • array: T[]

      The array of interest.

    • index: number

      The index at which to insert the value. Negative values are taken as an offset from the end of the array.

    • value: T

      The value to set at the specified index.

      Complexity

      Linear.

      Undefined Behavior

      An index which is non-integral.

      Example

      import { ArrayExt } from '@lumino/algorithm';

      let data = [0, 1, 2];
      ArrayExt.insert(data, 0, -1); // [-1, 0, 1, 2]
      ArrayExt.insert(data, 2, 12); // [-1, 0, 12, 1, 2]
      ArrayExt.insert(data, -1, 7); // [-1, 0, 12, 1, 7, 2]
      ArrayExt.insert(data, 6, 19); // [-1, 0, 12, 1, 7, 2, 19]

    Returns void

Generated using TypeDoc