Generally,."Operator to access the property value of an object. The value on the left of the vertex operator is the object for accessing its attributes. The value on the right of the vertex operator should be the attribute name. The properties of an object are similar to those of a variable. You can store the value or read the value from it.
① Attribute Enumeration
For/inLoop provides a way to traverse object attributes. The following code shows a function that can be used to list all attribute names of an object:
Function displaypropertynames (OBJ) {var names = ""; for (VAR name in OBJ) Names + = Name + "\ n"; alert (names );}
Note that the for/in attributes are not listed in a specific order. Although it can enumerate all user-defined attributes, it cannot enumerate some predefined attributes or methods.
② Check the existence of attributes
InOperators can be used to test the existence of an attribute. For example
If ("X" in O) o. x = 1;
In fact, the above statements are rare. If the query does not have an attribute, the undefined value is returned. Therefore, the above Code is usually written in this way.
If (O. X! = Undefined) o. x = 1;
Note that an attribute may also exist but is still undefined. For example, o. x = undefined; Attribute x already exists but has no value.
③ Delete attributes
AvailableDeleteOperator to delete the attributes of an object:
Delete book. Chapter2;
Deleting a property actually removes the property from the object. After deletion, the for/in loop does not enumerate this attribute, and the in operator does not detect this attribute.