语法:
...数组/对象
函数调用代替apply
- 如果有将数组元素依次作为函数参数,一般会选择用apply调用,但有了
...
,直接用...
即可;
function xxx(a,b,c){}
var arr = [a,b,c]
xxx(...arr)
拷贝数组
var arr = [2,3,4]
var arr1 = [...arr] // [2,3,4]
合并数组,相当于Array.concat
let a = [1,2]
let b = [6,7]
let c = [...a,...b] // [1,2,6,7]
解构赋值(展开运算符必须放在最后一位)
let [a,b,...c] = [1,3,4,5,6];
let {a1,b1,...c1} = {b1:3,a1:2,f:3,d:5};
console.log(c); // [4,5,6]
console.log(c1); // {f: 3, d: 5}
网友评论