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]
这是我的签名
浙公网安备 33010602011771号