Jump to content

help understanding two demmensional arrays


necro
 Share

Recommended Posts

could anyone help me in understanding how to create a two dimensional array (an array of arrays as it were) and then how to access info back out of it?

var myarray = new Array(3); // main arrayfor (var i = 0; i < 3; i++) myarray[i] = new Array(3); // sub arrays

now we own 3 arrays with 3 sub arrays: myarray[0] -> [0][1][2]myarray[1] -> [0][1][2]myarray[2] -> [0][1][2]

myarray[0][0] = "horse";myarray[1][2] = "cat";myarray[2][1] = "dog";if (myarray[2][1] == "dog") alert(myarray[0][0]);

etc. hope this help? :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...