js如何让数组左移一格或右移一格
作者:互联网
function toLeft([first, ...rest]) {
return [...rest, first];
}
function toRight(arr) {
return [arr.pop(), ...arr];
}
const arr = [1, 2, 3, 4, 5];
console.log(arr);
console.log(toLeft(arr));//[2, 3, 4, 5, 1]
console.log(toRight(arr));//[5, 1, 2, 3, 4]
标签:右移,...,arr,console,log,function,左移,js,return 来源: https://www.cnblogs.com/zxcv123/p/16070842.html