how to make 2D arrays in javascript

Computer builds, hardware and software discussion or troubleshooting, including peripherals. Essentially a general place to talk about desktop computers.
Locked
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

how to make 2D arrays in javascript

Post by Red Squirrel »

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

Code: Select all

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]);
[code]

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. 

[color=#888888][size=85]Archived topic from Iceteks,  old topic ID:3987, old post ID:32744[/size][/color]
Honk if you love Jesus, text if you want to meet Him!
Locked