How can I define an array in JavaScript?

Answer Posted / madhav arora

Arrays can be defined in following three ways :

1. regular method:
ex: var arrayname=new Array();
arrayname[0]="abc";
arrayname[1]="pqr";
arrayname[2]="xyz";

2.condensed method:
ex: var arrayname=new Array("abc","pqr","xyz");

3.literal method:
ex:var arrayname=["abc","pqr","xyz"];

Is This Answer Correct ?    16 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is stack in javascript?

505


Create an array in javascript with a list of 4 colors, assign that array to the variable, ‘colors’.

449


Where can I learn javascript for free?

504


How to create a confirmation box?

548


Name some of the ways in which Type Conversion is possible?

539






Can you explain about screen object?

552


Taking a developer's perspective, do you think that that javascript is easy to learn and use?

484


Write the code for adding new elements dynamically?

604


What and where are the best javascript resources on the web?

494


What is a global variable in programming?

501


Explain why "self" is needed instead of "this".

526


How can you create an Object in JavaScript?

568


What is difference between api and library?

489


Name some of the built-in methods and the values returned by them.

563


How do I use an external javascript file?

512