Click to See Complete Forum and Search --> : multidimensional arrays in javascript (resolved)
tr0n
Jul 26th, 2002, 07:32 AM
i know that to create multidimensional arrays in javascript you have to create an array of arrays, seeing as it doesn't support them properly. so, if i wanted to create a 4x500 array like this:
Col0 Col1 Col2 Col3
Row0 Row0 Row0 Row0
Row1 Row1 Row1 Row1
Row2 Row2 Row2 Row2
.... .... .... ....
Row499 Row499 Row499 Row499
would i have to do this:
var arrStuff = new Array(new Array(3), new Array(3), new Array(3), new Array(3)...500 times)
if so, bugger that! :p
bsw2112
Jul 26th, 2002, 02:14 PM
maybe you can do something like this
<html><head>
<script>
function createArray()
{
var arrStuff = new Array();
for (i=0;i<500;i++)
{
arrStuff[i] = new Array();
}
//populate
for (i=0;i<500;i++)
{
for (x=0;x<4;x++)
{
arrStuff[i][x] = "hello"
}
}
alert(arrStuff[50][3]);
}
</script>
</head>
<body>
<a href ="#" onClick="createArray()">click</a>
</body>
</html>
i am not sure if the logic is correct
regards
bsw2112
tr0n
Jul 29th, 2002, 03:24 AM
thanks, i'll try playing around with that :)
progressive
Jul 29th, 2002, 07:46 AM
Why can't you have an array
like:-
my_array = new Array(new Array(499), new Array(499), new Array(499), new Array(499))
visualised like:
row0, 0 - 499
row1, 0 - 499
row2, 0 - 499
row3, 0-499
tr0n
Jul 29th, 2002, 10:34 AM
yeah, i tried that, but that ended up creating an array like this:
row0,0 row0,1 row0,2 row0,3.....row0,499
row1,0 row1,1 row1,2 row1,3.....row1,499
rather than
row0,0 row0,1 row0,2 row0,3
row1,0 row1,1 row1,2 row1,3
...
row499,0 row499,1 row499,2 row499 3
progressive
Jul 29th, 2002, 10:38 AM
Ok, I undertsand now what you where trying to do, after helping you with your other thread ! ;)
How did you get on with Math.round ?
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.