Re: 3d array in javascript
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: 3d array in javascript

From: RobG <rgqld@iinet.net.au>
Date: Tue Apr 18 2006 - 07:57:15 CEST

hardik said on 18/04/2006 2:34 PM AEST:
> how i can set 3*3 array in javascript i have tried this but didnt work
>
> <Script>
> var a[2][2][2]=new array()
> <\Script>

If you already had an array called 'a' with an array at index 2 and
another array at that array's index 2, then you could create an array at
index 2 of that last array.

But you haven't, so you have a script error. Also, the built-in array
object has a capital 'A' (to signify that you can use it as a
constructor perhaps).

To save on typing and potential typos, use an initialiser:

     var a = [];
     a[2] = [];
     a[2][2] = [];
     a[2][2][2] = [];

A one dimension array 1x3:

   var a = ['A', 'B', 'C'];

A two dimension array 2x3:

   var a = [
             ['A', 'B', 'C'],
             ['D', 'E', 'F']
           ];

A three dimension array 2x3x3:

   var a = [
             [
                ['a','b','c'],
                ['d','d','f'],
                ['g','h','i']
             ],
             [
                ['j','k','l'],
                ['m','n','o'],
                ['p','q','r']
             ]
           ]

   alert( a[0][1][2] ); // shows f

Keep going and it gets much harder to read...

-- 
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ>
Received on Mon May 1 05:05:33 2006