javascript array delcaration

Posted on 2011-09-07
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?
Question by:costaf
LVL 22

Expert Comment

by:Om Prakash
ID: 36495526

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

LVL 14

Expert Comment

ID: 36495539
1. It is correct.

2. Its not multidimensional array. To create multidimensional one:


Accepted Solution

zvytas earned 500 total points
ID: 36495556
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));
LVL 82

Expert Comment

ID: 36495586
a={"0":new Array(2),"1":new Array(4)}

Author Closing Comment

ID: 36495679
thank you very much to you all!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

914 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

16 Experts available now in Live!

Get 1:1 Help Now