i'm attempting to read from a global 2d array in javascript and it gives me "Cannot read property 'undefined' of undefined".
Here's how I'm defining my array:
var cell = {visited:false, left:true, top:true, right:true, bottom:true}
var cells = new Array(10);
for (i = 0; i < 10; i++) //Initiate 2d cells array.
{
cells[i] = new Array(cell,cell,cell,cell,cell,cell,cell,cell,cell,cell);
}
I'm then accessing it later like this:
if(x != 0) //Left
{
if(cells[x-1][y].visited == false)
{
//Do something
}
}
x and y are never out of bounds of the defined array so I'm not sure why this is occuring.
Thanks!
varit won't be global.varkeyword before variable name