首先我有一个像这样的数组:
arr = [[r,g,b,a],[r,g,b,a],[r,g,b,a],[r,g,b,a],[r,g,b,a],[r,g,b,a]]
我可以使用“压平”它
arr = Array.prototype.concat.apply([],arr)
或者使用 for-next 循环和 push.apply
然后我得到:
[r,g,b,a,r,g,b,a,r,g,b,a,r,g,b,a,r,g,b,a]
如何尽可能简单地将其恢复为原始格式?
最佳答案
var newArr = [];
while(arr.length){
newArr.push(arr.splice(0,4));
}
关于javascript - 一维到二维数组javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5868445/