Ways to create Arrays:
1. simple constructor creates an empty array of zero length:
myList = new Array();
i. now you can assign values by index, e.g.:
myList[0] = 2002;
myList[1] = "Steve";
etc.
ii. or assign them all at once with in a comma delimited list:
myList = [2002, "Chris","Denise","Jenny","Pepper","Rudy"];2. constructor with a single numeric argument creates an empty array with the specified number of empty elements:
myList = new Array(5);
i. now you can assign values ...
3. constructor with comma-separated arguments:
myList = new Array(2002, "Chris","Denise","Jenny","Pepper","Rudy");4. simply assign a comma-separated list inside square brackets (an array literal) to a variable:
myList = ["Chris","Denise","Jenny","Pepper","Rudy", 400 * Math.PI];
SPECIAL:
Create an ASSOCIATIVE ARRAY, a list of named elements (a.k.a, a hash):
hash = new Array();
hash["name"] = "john"
hash["age"] = 27All at once:
hash = new Array();
hash = {
name: "john",
age: 27
}Access Associative array:
txt = hash["name"]
would set the value of the variable, txt, to "john".