ES6 扩展运算符

ES6的扩展运算符则可以看作是rest参数的逆运算。可以将数组转化为参数列表。

如:console.log(1,...[2,3,4],5) //1 2 3 4 5 

用于合并数组:

[1,2, ...more] //ES6

与解构赋值结合: 
  

let [first,...rest] = [1,2,3,4,5];
first //1
rest  //[2,3,4,5]

如果将扩展运算符用于数组复制,只能放在参数最后一位,否则会报错

[...rest,last]=[1,2,3,4,5]
//报错
 
原文地址:https://www.cnblogs.com/chendaoyin/p/8807879.html