📌  相关文章
📜  javascript数组将元素移动一位 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:03:19.927000             🧑  作者: Mango

代码示例1
// Move element '3' to where currently '1' is
const numbers = [ 1, 2, 3, 4, 5 ]
const numbersOriginal = Object.assign(numbers)
const sourceIndex = 2
const targetIndex = 0
numbers.splice(targetIndex, 0, numbers.splice(sourceIndex, 1)[0])
console.log(numbersOriginal)
console.log(numbers)