@eroyeroy/utils - v0.1.0
    Preparing search index...

    Function insertArrayItem

    • Returns a new array with item inserted at index. Defaults to appending at the end.

      Type Parameters

      • T

      Parameters

      • array: readonly T[]

        The source array.

      • item: T

        The item to insert.

      • index: number = array.length

        Position to insert at (must be between 0 and array.length).

      Returns T[]

      insertArrayItem([1, 2, 4], 3, 2) // => [1, 2, 3, 4]
      insertArrayItem([1, 2, 3], 4) // => [1, 2, 3, 4]