es6 三点扩展运算符

es6 得重大更新 三个点 很神奇,放在不同的位置又不同的作用

放在数组或对象前,用于展开数组或对象

 console.log(...['c','dd']);//c dd
 let b = {'c':'c','dd':'d'};
console.log({...{'c':'c','dd':'d'},v:'v'});//{c: "c", dd: "d", v: "v"}
//    也可以合并
    let f = ['c','d','a','f'];
    let [cc,...dd] = f;
    console.log(cc);//c
    console.log(dd);// ["d", "a", "f"]
//    类似于这样定义变量
    let [ee,ff] = ['eeeeeeee',['ccccc','ffffff'] ];
    console.log(ee);//eeeeeeee
    console.log(ff);//["ccccc", "ffffff"]
function show(b,...c){//扩展运算符放到函数的形参数前,可以接受到多个参数,也可以合并多个参数变成一个数组,
    console.log(c);//[2, 3, 4, 5, 3]
}
show(1,2,3,4,5,3)

你可能感兴趣的:(es6,学习笔记)