Solved

javascript array delcaration

Posted on 2011-09-07
5
158 Views
Last Modified: 2012-06-21
can anyone tell me if the declaration of an array :

a=new Array(2,4);  is correct? -is it a bi-dimensional array?
0
Comment
Question by:costaf
5 Comments
 
LVL 22

Expert Comment

by:Om Prakash
Comment Utility

var a  = new Array(2);  

for 2 dimensional array, you can do the following:
var a  = new Array(2);  

for (i=0; i <4; i++)
a[i]=new Array(4)

Open in new window

0
 
LVL 14

Expert Comment

by:R-Byter
Comment Utility
1. It is correct.
http://www.w3schools.com/js/js_obj_array.asp

2. Its not multidimensional array. To create multidimensional one:
http://stackoverflow.com/questions/2529865/javascript-multidimensional-array

Regards
0
 
LVL 5

Accepted Solution

by:
zvytas earned 500 total points
Comment Utility
The declaration is syntactically correct, however it's not a bi-dimensional array. What you created is an array with two elements - 2 and 4. If you want a bi-dimensional array you should do the following:

a=new Array(new Array(4), new Array(4));
0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
a={"0":new Array(2),"1":new Array(4)}
0
 
LVL 2

Author Closing Comment

by:costaf
Comment Utility
thank you very much to you all!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now