Object Operators

Object Operators

Operator Description
Object Literal {p1:x,p2:y,...} You can create an object by enclosing a list of property name/value pairs in braces. For example, {length:3,width:2,height:4}. This expression creates an object with three properties named length, width, and height.
new new x() Another way to create an object is to use the new operator in conjunction with an object constructor function.
Property x.y Once you have created an object, you can refer to its properties by placing a period after the object name followed by the property name. For example, obj.length references the property named length in the object named obj.
List Element x[y] You can access an object property using the List Element operator as well. This syntax is similar to using the Property operator except the operand y can evaluate to a property name instead of being a name literal. For example, obj["length"] is the same as obj.length. This is also equal to obj[y] as long as y is a variable with the value "length".
deletee delete x.y Delete specific object properties. For example, the expression delete obj.length removes the property named length from the object named obj.