It's not so tricky to create a 2d array, you just need to go about it a little differently to some other langs. First, you want to create the first dimension. Next, you need to fill each element in this dimension with a second array. In my case, I've abstracted a screen. The first dimension is the rows, or y-coord. Each of these rows contains an array that holds all of the pixels in that line - the columns. This code simply creates a 320x200 array and fills it with a simple xor pattern. Of course, the other way to do it is to do what the compiler does - simply allocate a block of memory and then index into it yourself. The imageData object of the canvas does this - it has a 1d array that represents the pixels. So (y*width*4)+(x*4) will give you the index of the pixel you want. Since it's a 32bit pixel, there's 4 bytes for each one. It saves indexing and is much quicker and easy enough enough. That said, here's the code I promised earlier.
var screenArray;
function mInit()
{
var x, y, width=320, height=200;
var result = new Array;
for (y=0; y<height; y++)
{
result\[y\] = new Array;
for (x=0; x<width; x++)
{
result\[y\]\[x\] = x^y;
}
}
screenArray = result;
console.log(screenArray);
}
Make it work. Then do it better - Andrei Straut