Closed Thread Icon

Preserved Topic: Multi-dimensional arrays and length. (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=18024" title="Pages that link to Preserved Topic: Multi-dimensional arrays and length. (Page 1 of 1)" rel="nofollow" >Preserved Topic: Multi-dimensional arrays and length. <span class="small">(Page 1 of 1)</span>\

 
jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 06-13-2001 17:51

Couple of questions. First of all, does javascript handle multiple dimension arrays the same as java? ie. arrays of arrays.

Secondly, is there a length attribute to arrays that is widely supported throughout all browsers? ie. arrayName.length



-jiblet

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 06-13-2001 18:18

Yup and yup. Array.length works fine, and in fact, you can *set* it in order to truncate an array.

Nocturne
Nervous Wreck (II) Inmate

From: Netherworld
Insane since: Dec 2000

posted posted 06-25-2001 20:11

How exactly can I create a two dimensional array in Javascript? Is it possible at all?

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 06-25-2001 20:16

I'm not very experienced with javascript syntax, and so I don't know if you even need to declare your arrays (in PHP u can just start filling them without a declaration...) but assuming you need a declaration, you would define a 10 x 10 array like so:

test = new Array(10);
for(i = 0; i < 10; i++) {
test[i] = new Array(10);
}

This reflects the answer to my question that multi-dimensional arrays are actually arrays of arrays.

In this example...

test is a pointer to an array of arrays.
test[0] through test[9] are pointers to 10 separate arrays.
test[0][0] refers to the 0 element of the array pointed to by test[0].

Does that make sense? BTW, there may be a way to define multi-dimensional arrays quickly... i'm sure someone will chime in if so.

-jiblet

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 06-25-2001 20:40

<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
<!-- ;
// Written by mr.maX, http://www.max.co.yu/
testArray = [["bla1a","bla2a"], ["bla1b","bla2b"], ["bla1c","bla2c"]];
for (i=0; i < testArray.length; i++) {
&nbsp;&nbsp;&nbsp;&nbsp;for (j=0; j < testArray[i].length; j++) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.write(testArray[i][j]+" ");
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;document.write("<BR>");
}
// -->
</SCRIPT>

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 06-25-2001 22:33

You can also simulate this by creating objects ie:

function myObj() {
this.color = blue;
this.height = 100;
this.width = 200;
}

daObj = new myObj;

stuff = new Array;
stuff[0] = daObj;

alert(stuff[0].color);
// returns "blue"


Walking the Earth like Kane

« BackwardsOnwards »

Show Forum Drop Down Menu