Property access

Provides a reference for the syntax used to access properties in OPL.

There are two ways of accessing a property value.

Table 1. Property access syntax
Syntax Effect
value.name

Returns the value of the name property of value, or the undefined value if this property is not defined. See Identifiers for the syntax of name.

Examples:

str.length getCar().name

Because name must be a valid identifier, this form cannot be used to access properties which do not have a valid identifier syntax. For example, the numeric properties of an array cannot be accessed this way:

myArray.10 // Illegal syntax

For these properties, use the second syntax.

value[name]

Same as the previous syntax, except that this time name is an evaluated expression which gives the property name.

Examples:

str["length"] // Same as str.length getCar()[getPropertyName()] myArray[10] myArray[i+1]