Click to See Complete Forum and Search --> : Declare multi-dimensional array


BananaQuaalude
08-12-2003, 03:38 PM
How do I declare a multi-dimensional array without initially entering any values into it?

I've tried:

var arrChange = new Array[[]]

which doesn't work.

thanks!

DJRobThaMan
08-12-2003, 03:53 PM
You mean something like this???

var i;
var first = newArray();
var second = newArray();
var all = second[first[i]];



I did it once for a class.
I can't remember if that's the right way to do it tho.


Assuming that's what u mean by a multi-dimensional array.

Anywayz, Hope it helps.


Lata

BananaQuaalude
08-12-2003, 04:14 PM
Okay, but I don't see the point of having the third array then. I only need two dimensions, so I can just assign the variables to each array separately, giving them each the same index number.

As in:

first[0] = variable1a
second[0] = variable1b

There has to be a way to declare a two-dimensional array without putting variables into it initially, so I can later assign like this:

arrData[0][0] = variable1a
arrData[0][1] = variable1b

???

pyro
08-12-2003, 04:20 PM
Yep, try this:

<script type="text/javascript">
chars = new Array();
chars[0] = new Array(); //set chars[0] to be a new array
chars[0][0] = "a";
chars[0][1] = "b";
chars[0][2] = "c";
chars[1] = new Array(); //set chars[1] to be a new array
chars[1][0] = "1";
chars[1][1] = "2";
chars[1][2] = "3";
alert (chars[0][1]); //will alert the letter 'b'
alert (chars[1][2]); //will alert the number '3'
</script>

Charles
08-12-2003, 04:22 PM
Originally posted by BananaQuaalude
There has to be a way to declare a two-dimensional array without putting variables into it initially, Not really. You have to make an array full of empty arrays.

<script type="text/javascript">
<!--
doubleWide = new Array([],[],[]);
doubleWide[0][1] = Math.PI;
alert (doubleWide[0][1]);
// -->
</script>

BananaQuaalude
08-12-2003, 04:31 PM
Groovy.

Thanks to everyone!

pyro
08-12-2003, 04:32 PM
Yep, yep... :)