Mayfield Global Knowledge Center



How do I create an array in JavaScript?

Arrays can be created with the Array() constructor function. Once you create the array, any number of indexed elements can be easily assigned to the array:

var array1 = new Array();
array1[0] = "JavaScript is cool!";
array1[1] = 10.5;
array1[2] = false;
array1[3] = { x:10, y:5 };

Arrays can also be initialized by passing array elements to the Array() constructor function:
var array1 = new Array("JavaScript is cool!", 10.5, false, { x:10, y:5 });

 

Would you like to...


del.icio.us

Print this page Print this page

Email this page Email this page

Post a comment Post a comment

Subscribe me

Add to favoritesAdd to favorites

User Opinions (5 votes)

40% thumbs up 60% thumbs down

How would you rate this answer?

Helpful
Not helpful
Thank you for rating this answer.