js如何交换数组元素的位置
let arr1 = [1, 2, 3, 4]
function changePos(arr, a, b) {
[arr[b], arr[a]] = [arr[a], arr[b]]
}
changePos(arr1, 0, 1)
console.log(arr1)
这是我的签名
let arr1 = [1, 2, 3, 4]
function changePos(arr, a, b) {
[arr[b], arr[a]] = [arr[a], arr[b]]
}
changePos(arr1, 0, 1)
console.log(arr1)