Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > 3d array in javascript

Reply
Thread Tools

3d array in javascript

 
 
hardik
Guest
Posts: n/a
 
      04-18-2006
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.

 
Reply With Quote
 
 
 
 
Hal Rosser
Guest
Posts: n/a
 
      04-18-2006

"hardik" <> wrote in message
news: 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]);


 
Reply With Quote
 
 
 
 
Hal Rosser
Guest
Posts: n/a
 
      04-18-2006

"Hal Rosser" <> wrote in message
news:Nz_0g.31359$. ..
>
> "hardik" <> wrote in message
> news: 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.

>
>



 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      04-18-2006
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>
 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      04-18-2006

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>




 
Reply With Quote
 
hardik
Guest
Posts: n/a
 
      04-18-2006
thank u friends

 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      04-18-2006
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/
 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      04-18-2006
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
 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      04-18-2006
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.
 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      04-18-2006

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!



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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const and array of array (of array ...) Mara Guida C Programming 3 09-03-2009 07:54 AM
Array function SPLICE doesn't work with Select->OPTIONS array. JavaScript BrianP Javascript 2 09-18-2005 04:20 AM
Array and Hash (Associative array) in JavaScript v.3.0 VK Javascript 36 07-30-2005 03:21 PM
length of an array in a struct in an array of structs in a struct in an array of structs Tuan Bui Perl Misc 14 07-29-2005 02:39 PM
Length of Array of Array of Array Tom Perl Misc 3 12-20-2004 05:23 PM



Advertisments