您的位置:首页 > 其它

对象扩展运算符和rest运算符

2018-01-30 21:26 239 查看
对象扩展运算符

实例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);


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: