HTML and CSS Reference
The bracket notation allows you to use either a string or variable as the index value,
whereas the dot notation requires the literal name of the property.
cat = new Object();
c = "color"
cat["name"] = "Powder" ;// same as cat.name = “Powder”
cat[c] = "gray"; // same as cat.color = “gray”;
document.write( cat.name +"is"+ cat.color + "<br />");
document.write( cat["name"] +"is"+ cat[c] + "<br />");
A new cat object is instantiated.
The variable c is assigned the string “color”.
The square brackets contain an index value that also represents a property for the
object. We could have written this as cat.name = “Powder”.
The variable c is used as the index value within the square brackets. Using this
notation would allow you to easily change the value of the variable, thereby
changing the property of the object.
A property of the cat object can be accessed directly with the dot notation, or rep-
resented with a string or variable within the square brackets (see Figure 9.9).
Figure 9.9 Properties of the cat object accessed with bracket or dot notation.
An array can consist of another set of arrays. Take, for example, a row of seats in a movie
theater. One row of seats would represent a one-dimensional array, but the theater has
more than one row. To get to your seat you need to not only know what row, but the
number of the seat as well.
To create a two-dimensional array, each row is a new array. To find an element in the
array we will use two index values, one for the row and one for the column; for example,
array_name represents the first element in the first row. The array in Figure 9.10
consists of three rows and three columns: