您现在的位置:首页 >> 前端 >> 内容

对象扩展运算符和rest运算符代码实例讲解

时间:2018/1/31 13:45:42 点击:

  核心提示:对象扩展运算符实例1:function f(...arg){console.log(arg[0]);console.log(arg[1]);console.log(arg[2]);console.lo...

对象扩展运算符

实例1:

function f(...arg){
    console.log(arg[0]);
    console.log(arg[1]);
    console.log(arg[2]);
    console.log(arg[3]);
}

f(1,2,3);

对象扩展运算符和rest运算符代码实例讲解

实例2:

let arr1 = ['www','qxb','com'];
let arr2 = [...arr1];
console.log(arr2);
arr2.push('ljj');
console.log(arr2);
console.log(arr1);

对象扩展运算符和rest运算符代码实例讲解

rest运算符

实例1:

function f(first,...arg){
    console.log(arg.length);
}

f(0,1,2,3,4,5,6,7);

对象扩展运算符和rest运算符代码实例讲解

实例2:

function f(first,...arg){
    for(let val of arg){
        console.log(val);
    }
}

f(0,1,2,3,4,5,6,7);

对象扩展运算符和rest运算符代码实例讲解

作者:网络 来源:zjsfdx的博客