473,379 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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 29151

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: JesusFreak | last post by:
From: us_traveller@yahoo.com (JesusFreak) Newsgroups: microsoft.public.scripting.jscript Subject: toolbar script problem NNTP-Posting-Host: 192.92.126.136 Recently, I downloaded the following...
13
by: Kevin | last post by:
Help! Why are none of these valid? var arrayName = new Array(); arrayName = new Array('alpha_val', 1); arrayName = ; I'm creating/writing the array on the server side from Perl, but I
10
by: John Ortt | last post by:
Hi Everyone, I have created a Javascript menu for my site which uses frames. The first stage loads fine but I want two drill down menus ("About Me Menu" and "Projects Menu"). The pages load...
3
by: John Ortt | last post by:
I appologise for reposting this but I have been trying to find a solution all week with no avail and I was hoping a repost might help somebody more knowledgable than myself to spot the message... ...
9
by: mprocopio | last post by:
Fellow JavaScripters, I am looking for code or implementation ideas for converting an integer variable to a four-byte array. I'm porting some of my code from C#, where I make use of their...
8
by: J. B. Moreno | last post by:
What's the best (i.e. fastest) way to find out if an array contains a given value? Other than looping, the only way I know to do it is to use an associative array/hash instead.... Is there a...
2
by: BrianP | last post by:
Hi, I have had to invent a work-around to get past what looks like a JavaScript bug, the malfunctioning Perl-like JavaScript array functions including SPLICE() and UNSHIFT(). I have boiled it...
1
by: _andrea.l | last post by:
Salve a tutti, Ho un array di valori in un array javascript: lista=pippo lista=nando lista=.... Come inviare questa lista ad una pagina scritta in php? magari cliccando un bottone "invia...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
7
by: sosamv | last post by:
Hi all!, I'm creating a app with PHP and MySQL, the system administrator is capable of creating profiles, on each profile we create, we add a custom access menu (a javascript tree view menu), theres...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.