Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2d arrays 1

Status
Not open for further replies.

newbiescooby

Technical User
Dec 5, 2006
13
0
0
NZ
Hi

I'm trying to set a 2d array and it's not working correctly.

my code is:

var ContentArray = new Array(9); //Define array
for(var i=0;i<=9;i++)
{
ContentArray = new Array(9); // create 2d array
}
ContentArray[0,0]="1";
ContentArray[0,1]="2";
ContentArray[1,0]="3";
alert(ContentArray[0,0] + " " + ContentArray[0,1] + " " + ContentArray[1,0]);


but the alertbox brings back 3 2 3, so it seems to be writing the 2nd column in value in all rows.

Canb someone help me out and tell me why each cell is not independant?
 
[tt]var ContentArray = new Array(9); //Define array
for(var i=0;i<=9;i++)
{
ContentArray = new Array(9); // create 2d array
}
ContentArray[0][0]="1";
ContentArray[0][1]="2";
ContentArray[1][0]="3";
alert(ContentArray[0][0] + " " + ContentArray[0][1] + " " + ContentArray[1][0]);[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top