github:https://github.com/sindresorhus/array-move
api
arrayMove(array, from, to)
- array:原数组
- from:移动元素的索引。 如果为负,索引将从末尾开始
- to:移动后的位置。 如果为负,索引将从末尾开始
Usage
const arrayMove = require('array-move');const input = ['a', 'b', 'c'];const array1 = arrayMove(input, 1, 2);console.log(array1);//=> ['a', 'c', 'b']const array2 = arrayMove(input, -1, 0);console.log(array2);//=> ['c', 'a', 'b']const array3 = arrayMove(input, -2, -3);console.log(array3);//=> ['b', 'a', 'c']
