欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

es6语法总结-解构赋值

程序员文章站 2022-07-16 22:08:25
...
    function sum(x,y,z){
        let total = 0;
        if(x)total+=x;
        if(y)total+=y;
        if(z)total+=z;

        console.log(`total:${total}`);
    }
    sum(5,'',9)

    function sum2(...m){
        let total = 0;
        for(var i of m){
            total+=i;
        }
        console.log(`total:${total}`)
    }
    sum2(4,8,9,10);

    let sum3 = (...m)=>{
        let total = 0;
        for(var i of m){
            total+=i;
        }
        console.log(`total:${total}`);
    }
    sum3(4,8,9,10);

//    var [x,y] = [4,8]

    console.log(...[4,8]);

    let arr1 = [1,3];let arr2 = [4,8];
    console.log("concat: "+arr1.concat(arr2));

    console.log([...arr1,...arr2]);

//    var [x,y] = [4,8];

    var [x,...y] = [4,8,10,30];

    let [a,b,c]= 'es6';

    let xy =  [...'es6'];