扩展运算符允许一个表达式在期望多个参数(用于函数调用)或多个元素(用于数组字面量)或多个变量(用于解构赋值)的位置扩展
ES3 / ES5 合并数组
var params = ['hello', true, 7]
var other = [1, 2].concat(params) //concat() 方法用于连接两个或多个数组。
console.log(other)
//打印结果:(5) [1, 2, "hello", true, 7]
ES6 利用扩展运算符合并数组
let params = ['hello', true, 7]
let other = [1, 2, ...params]
console.log(other)
//打印结果:(5) [1, 2, "hello", true, 7]





网友评论