Function insert

  • Can insert an array or a single element. Negative indices count backwards from the end of the array.

    Remarks

    Non-integer or out of bounds indices return the array unchanged. If index equals the length of the array, then elems will be appended to the end.

    Example

    import * as A from "flurp/array";

    const insertOne = A.insert(2, 10);
    insertOne([0, 1, 2, 3, 4]); // [0, 1, 10, 2, 3, 4]

    const insertMulti = A.insert(2, [10, 11, 12]);
    insertMulti([0, 1, 2, 3, 4]); // [0, 1, 10, 11, 12, 2, 3, 4]

    Type Parameters

    • T

    Parameters

    • index: number
    • elems: T | T[]

    Returns ((arr: readonly T[]) => T[])

      • (arr: readonly T[]): T[]
      • Parameters

        • arr: readonly T[]

        Returns T[]