展开操作符

2020-06-17  本文已影响0人  darkTi

语法: ...数组/对象

函数调用代替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}
上一篇下一篇

猜你喜欢

热点阅读