Move an array item to a different position
$ npm install array-move
const arrayMove = require('array-move');
const input = ['a', 'b', 'c'];
arrayMove(input, 1, 2);
//=> ['a', 'c', 'b']
arrayMove(input, -1, 0);
//=> ['c', 'a', 'b']
arrayMove(input, -2, -3);
//=> ['b', 'a', 'c']
Returns a new array with the item moved to the new position.
Moves the item to the new position in the array
array. Useful for huge arrays where absolute performance is needed.
Type: Array
Type: number
Index of item to move. If negative, it will begin that many elements from the end.
Type: number
Index of where to move the item. If negative, it will begin that many elements from the end.