Function arrayMoveItem

  • Moves a particular item in an array up or down (move>0=down, move<0=up). Changes the array itself.

    const array = ['a', 'b', 'c'];

    arrayMoveItem(array, 'a', +1); //['b', 'a', 'c']
    arrayMoveItem(array, 'a', -1); //['a', 'b', 'c']

    arrayMoveItem(array, 'b', -1); //['b', 'a', 'c']
    arrayMoveItem(array, 'b', +1); //['a', 'c', 'b']

    arrayMoveItem(array, 'c', -1); //['b', 'c', 'b']
    arrayMoveItem(array, 'c', +1); //['a', 'b', 'c']

    Type Parameters

    • A extends T[]

    • T

    Parameters

    • array: A
    • item: T
    • move: number

    Returns A

Generated using TypeDoc