Function moveArrayItems

  • Moves items of an array in place (like Array.prototype.sort): the items at indices keep their order and are inserted in front of insertBefore (an index of the array before the move, array.length = at the end).

    Type Parameters

    • T

    Parameters

    • array: T[]

      the array to change

    • indices: readonly number[]

      ascending, unique indices (normalizeRowIndices)

    • insertBefore: number

      0 … array.length

    Returns number

    the new index of the first moved item (-1 if nothing was given)

    Example

    const list = ["a", "b", "c", "d", "e"];
    moveArrayItems(list, [1, 3], 5); // 3
    list; // ["a", "c", "e", "b", "d"]

    Since

    1.1.95