对象扩展运算符
实例1:
function f(...arg){
console.log(arg[0]);
console.log(arg[1]);
console.log(arg[2]);
console.log(arg[3]);
}
f(1,2,3);
实例2:
let arr1 = ['www','qxb','com'];
let arr2 = [...arr1];
console.log(arr2);
arr2.push('ljj');
console.log(arr2);
console.log(arr1);
rest运算符
实例1:
function f(first,...arg){
console.log(arg.length);
}
f(0,1,2,3,4,5,6,7);
实例2:
function f(first,...arg){
for(let val of arg){
console.log(val);
}
}
f(0,1,2,3,4,5,6,7);
本文介绍了JavaScript中对象扩展运算符和rest运算符的应用。通过具体实例展示了如何使用对象扩展运算符来复制数组,以及rest运算符如何收集不定数量的参数。
3512

被折叠的 条评论
为什么被折叠?



