For (var I = 0; I <len; I ++) can be replaced by for in.
For example:
Copy codeThe Code is as follows:
Var a = ["a", "B", "c"];
For (var el in ){
Alert (a [el]);
}
This is to cite all the elements in a. Of course, the above example can be used.
Copy codeThe Code is as follows:
For (var I = 0, len = a. length; I <len; I ++ ){
Alert (a [I]);
}
This method is cyclically listed, but sometimes this method does not necessarily work.
For example:
Copy codeThe Code is as follows:
Var a = {"first": 1, "second": 2, "third": 3 };
At this time, we can only use for in to make effort.
Whether an object can be used for in is exhaustive. We can use the propertyIsEnumerable attribute to determine whether an object can be used for in, which is described as follows:
PropertyIsEnumerable attributes
Returns a Boolean value indicating whether the specified attribute is a part of an object and whether the attribute is enumerable.
Copy codeThe Code is as follows:
Object. propertyIsEnumerable (proName)
Parameters
Object
Required. An object.
ProName
Required. The string value of an attribute name.
Description
If the proName exists in the object and you can use a... If the In loop is exhausted, the propertyIsEnumerable attribute returns true. If the object does not have a specified attribute or the specified attribute is not enumerable, The propertyIsEnumerable attribute returns false. Typically, predefined attributes are not configurable, and user-defined attributes are always configurable.
The propertyIsEnumerable attribute does not consider objects in the prototype chain.