Function insertAt

  • Inserts the value(s) at the given position. If the index is equal or higher than the array length, the value(s) will be appended. If the index is less than 0, the value(s) will be prepended.

    Note that the input array is being mutated.

    Since

    12.1.0

    See

    lodash.pullAt

    Returns

    The mutated array.

    Example

    const a = ["foo", "fizz"];
    insertAt(a, 1, "bar")
    // => ["foo", "bar", "fizz"]

    const b = ["foo", "fizz"];
    insertAt(b, 1, "bar", "bazz"))
    // => ["foo", "bar", "fizz", "bazz"]

    const c = ["foo", "fizz"];
    insertAt(c, 999, "bar"))
    // => ["foo", "fizz", "bar"]

    const d = ["foo", "fizz"];
    insertAt(d, -999, "bar"))
    // => ["bar", "foo", "fizz"]

    Type Parameters

    • TValue

    Parameters

    • array: TValue[]

      Array to modify.

    • index: number

      Index to insert at.

    • Rest ...values: TValue[]

      Value(s) to insert.

    Returns TValue[]

Generated using TypeDoc