一直都知道JS数组Array内置对象有一个concat方法,但是也没怎么研究过,今天偶然就看了看 concat是连接一个或多个数组 返回的是连接后数组的一个副本 var oldArr=[]; var arr=[[1,2,3],[4,5,6],[7,8,9],[10,11,12]]; var newArr=oldArr.conat(arr); console.log(newArr); console.log(oldArr);//[] 没有改变 于是乎 我又想到把数组的每一项都当成数组与oldAr…
Array.prototype.push.apply(a,b) 时常看到在操作数组的时候有这样的写法: var a = [1,2,3]; var b = [4,5,6]; a.push.apply(a, b); console.log(a) //[1,2,3,4,5,6] 其实这样的写法等价于: var a = [1,2,3]; var b = [4,5,6]; Array.prototype.push.apply(a, b); console.log(a) //[1,2,3,4,5,6] 这样…
763 down vote accepted +50 What happens under the hood is that when .slice() is called normally, this is an Array, and then it just iterates over that Array, and does its work. How is this in the .slice() function an Array? Because when you do: objec…