0

I have to convert about three hundred 1x10000 matrices into 100x100 matrices in the console with JavaScript. What is the most efficient way to split each matrix into a 100x100 matrix? I assume I need to somehow find the 100th instance of a , (comma) and replace that comma with ], [. I am just learning programming here.

var myArray = [2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 7, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 7, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 8, ... ]
4

2 回答 2

0

这很容易做到Array.slice

var myMatrix = Array();
for(i=0; i<100; i++) {
    myMatrix.push(myArray.slice(i*100, (i+1)*100));
}
于 2013-02-05T13:39:24.607 回答
0
var newArray = new Array();
var index= 0;
for (var i=0; i<100; i++)
{ 
    for (var j=0; j<100; j++)
    { 
       newArray[i,j] = myArray[index];
       index++;
    }
}
于 2013-02-05T13:41:01.603 回答