Monday, September 11, 2006

how to make 2D arrays in javascript??

A basic way to make a 2D array 20 by 20 is like this:

var UserBoard = new Array(20);
for(var i=0;i<=21;i++)
{
UserBoard[i]==new Array(20);
}
UserBoard[4,5]="test";
alert("test:" + UserBoard[4,5]);

Reason I'm posting this is just for reference purposes since I've been trying to do this for hours, thinking it was UserBoard[4][5] but it's UserBoard[4,5] that you access it by. Got this from here.

No comments: