JavaScript arrays
The following code creates an array named cars:
1 //Way One:2 varCars =NewArray ();3 4Cars[0] = "Volvo";5CARS[1] = "BMW";6CARS[2] = "QQ";7 8 //Way Two:9 varCars =NewArray ("Volvo", "BMW", "QQ");Ten One //Way Three: A varCars =Newarray["Volvo", "BMW", "QQ";
JavaScript Objects
Objects are separated by curly braces. Inside the parentheses, the properties of the object are defined in the form of name and value pairs (name:value). Attributes are separated by commas:
1 // Create object 2 var person = {id= "666666", firstname= "bills", Lastname= "Gates"};
The object (person) in the example above has three attributes: FirstName, LastName, and ID. Spaces and lines do not matter. Declarations can span multiple lines:
1 // Creating Objects 2 var person = {3 id= "666666",4 firstname= "Bills", 5 lastname= "Gates"6
Object properties are addressed in two ways:
1 name=person.lastname; 2 name=person["LastName"];
Use routines for arrays and objects in JavaScript