1) Conventional array
The classic conventional array looks like the following:
var mystudents=new Array() mystudents="Bob" mystudents="Jane" mystudents="Peter"
You can expand and contract the array as desired, by adding new array
With a conventional array, you have the option of presetting the array's
var mystudents=new Array(3)
In this case 3 array elements will automatically be created, each with a
2) Condensed array
The second way of defining an array is called a condensed array, and
var mystudents=new Array("Bob", "Jane", "Peter", 14, 54)
This is convinient if you know all the array element values in advance.
3) Literal arrays
//literal array with 3 elements var mystudents=["Bob", "Jane", "Peter"] //literal array with 5 elements (middle 3 with undefined values). var mystudents=["John", , , "Chris"]
As you can see, enclose all the array elements within an outter square
Literal arrays really shine when it comes to defining multi-dimensional
var myarray=[["New York", "LA", "Seattle"], China, Japan]
Here the first array element is actually a two dimensional array in itself
myarray //returns "LA"
Here's an array with its 1st element in turn being a 3 dimensional array:
var myarray=[[[2,4,6]], China, Japan]
Just remember, the more brackets you use, the deeper the hole you dig!