Property Access Expressions
A property access expression evaluates to the value of an object property or an array element. JavaScript defines two syntaxes for property access:
expression.identifierexpression[expression]
The first style of property access is an expression followed by a period and an identifier. The expression specifies the object, and the identifier specifies the name of the desired property. The second style of property access follows the first expression (the object or array) with another expression in square brackets. This second expression specifies the name of the desired property or the index of the desired array element. Here are some concrete examples:
varo={x:1,y:{z:3}};// An example objectvara=[o,4,[5,6]];// An example array that contains the objecto.x// => 1: property x of expression oo.y.z// => 3: property z of expression o.yo["x"]// => 1: property x of object oa[1]// => 4: element at index 1 of expression aa[2]["1"]// => 6: element at index 1 of expression a[2]a[0].x// => 1: property x of expression a[0]
With either type of property access expression, the expression
before the . or [ is first evaluated. If the value is null or undefined, the expression throws a
TypeError, since these are the two JavaScript values that cannot have
properties. If the value is not an object (or array), it is converted
to an object (see Wrapper Objects). If the object expression is followed by a dot and an identifier, the value of the property named ...