w3c 上这样定义concat():连接两个或更多的数组,并返回结果
我们可以这样:
var arr = [1,2,[3,4]]
[].concat(...arr) // 输出[1,2,3,4]
但是又有以下输出:
console.log(...[1,2,[3,4]]) // 输出 1 2 [3, 4]
这明显...[1,2,[3,4]] 的运算结果不是一个数组啊,怎么能直接使用[].concat(...arr)呢
------------------------答案分割线-----------------------------
先来看一个现象:
[].concat(1,2) // 输出[1,2]
[].concat(1,2,[3,4]) //输出[1,2,3,4]
真正的官网上给出的解释是:
When the concat method is called with zero or more arguments item1, item2, etc., it returns an array containing the array elements of the object followed by the array elements of each argument in order.
真正的 js 官网, 写得很清楚:
http://www.ecma-international...