剩余运算符
当函数参数个数不确定时,用 rest运算符
function rest1(...arr) {
for (let item of arr) {
console.log(item);
}
}
rest1(1, 2, 3);
// 结果
// 1
// 2
// 3
当函数参数个数不确定时的第二种情况
function rest2(item, ...arr) {
console.log(item);
console.log(arr);
}
rest2(1, 2, 3, 4, 5);
// 结果
// 1
// [2, 3, 4, 5]
解构使用
var [a,...temp]=[1, 2, 3, 4];
console.log(a);
console.log(temp);
// 结果
// 1
// [2, 3, 4]