469,282 Members | 1,749 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

3d array in javascript

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>
but it didnt work.
Bye & Best Of Luck.

Apr 18 '06 #1
10 28926

"hardik" <ha**********@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
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>
but it didnt work.


var a = new Array();
a[0]= new Array();
a[0][5] = new Array;
a[0][5][72]="<h3>Hello matey</h3>";
document.writeln(a[0][5][72]);
Apr 18 '06 #2

"Hal Rosser" <hm******@bellsouth.net> wrote in message
news:Nz*******************@bignews5.bellsouth.net. ..

"hardik" <ha**********@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
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>
but it didnt work.

var a = new Array();
a[0]= new Array();
a[0][5] = new Array;
a[0][5][72]="<h3>Hello matey</h3>";
document.writeln(a[0][5][72]);


You could loop through each array and declare new arrays for each element,
also
This is kinda clumsy - so I'm sure others will post a better solution.-
where I will take notes.
But the point is: its really an array of arrays [of arrays].... rather than
a single multidimensional array.

Apr 18 '06 #3
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>
Apr 18 '06 #4
VK

hardik wrote:
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>


See the samples of 2D and 3D arrays emulation at
<http://www.geocities.com/schools_ring/ArrayAndHash.html>
:-)

Apr 18 '06 #5
thank u friends

Apr 18 '06 #6
RobG said the following on 4/18/2006 1:57 AM:

<snip>
A two dimension array 2x3:
var a = [
['A', 'B', 'C'],
['D', 'E', 'F']
];


I think that Rob knows, without reading further, what this post says but
a is not a "two dimension array" as it is a simple array that has arrays
as members. Javascript arrays are linear in fashion and as such you
can't have multi-dimensional arrays.

Sorry Rob, but I had to post for posterity sake :)

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 18 '06 #7
Randy Webb wrote:
RobG said the following on 4/18/2006 1:57 AM:

<snip>
A two dimension array 2x3:
var a = [
['A', 'B', 'C'],
['D', 'E', 'F']
];

I think that Rob knows, without reading further, what this post says but
a is not a "two dimension array" as it is a simple array that has arrays
as members. Javascript arrays are linear in fashion and as such you
can't have multi-dimensional arrays.

Sorry Rob, but I had to post for posterity sake :)


That's fine. Others may say that a is a 2D array (matrix) that is
constructed using 2 one-dimensional JavaScript Array objects. :-)
--
Rob
Apr 18 '06 #8
RobG said the following on 4/18/2006 9:31 AM:
Randy Webb wrote:
RobG said the following on 4/18/2006 1:57 AM:

<snip>
A two dimension array 2x3:
var a = [
['A', 'B', 'C'],
['D', 'E', 'F']
];

I think that Rob knows, without reading further, what this post says
but a is not a "two dimension array" as it is a simple array that has
arrays as members. Javascript arrays are linear in fashion and as such
you can't have multi-dimensional arrays.

Sorry Rob, but I had to post for posterity sake :)


That's fine. Others may say that a is a 2D array (matrix) that is
constructed using 2 one-dimensional JavaScript Array objects. :-)


Tis true, but VK might say that "RobG says JS has a multi-dimensional
array" <shudder> <g>

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Light humor is good for the soul every now and then.
Apr 18 '06 #9
VK

Randy Webb wrote:
Tis true, but VK might say that "RobG says JS has a multi-dimensional
array" <shudder> <g>


I believe in the JavaScript Array being Dynamic, Sparse, Jagged and
now, and ever and forever!

:-D

P.S. Please, it is just a joke, not a call for discussion.

Apr 18 '06 #10
VK said the following on 4/18/2006 1:37 PM:
Randy Webb wrote:
Tis true, but VK might say that "RobG says JS has a multi-dimensional
array" <shudder> <g>
I believe in the JavaScript Array being Dynamic, Sparse, Jagged and
now, and ever and forever!


<g>
:-D

P.S. Please, it is just a joke, not a call for discussion.


Surprisingly enough, I took it that way :)
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 19 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by JesusFreak | last post: by
10 posts views Thread by John Ortt | last post: by
9 posts views Thread by mprocopio | last post: by
8 posts views Thread by J. B. Moreno | last post: by
104 posts views Thread by Leszek | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.