Usage like for(var i=0;iFor example:
var a = ["a" ,"b","c"];
for(var el in a){
alert(a[el]);
}
This is the exhaustive list All elements in a. Of course, in the above example, you can use
for(var i=0,len=a.length;ialert(a[i]);
}
Loop in this way listed, but sometimes this method may not work.
For example:
var a = {"first" :1,"second":2,"third":3};
At this time, you can only use for in to exhaust the list.
Whether an object can be exhaustively for in, we can judge it through the propertyIsEnumerable attribute. The description is as follows:
propertyIsEnumerable attribute
returns a Boolean value to indicate whether the specified property is part of an object. and whether the property is enumerable.
object.propertyIsEnumerable(proName)
Parameter
object
Required. an object.
proName
Required. A string value for the property name.
Explanation
If proName exists in object and can be enumerated using a For...In loop, then the propertyIsEnumerable property returns true. The propertyIsEnumerable property returns false if the object does not have the specified property or if the specified property is not enumerable. Typically, predefined properties are not enumerable, whereas user-defined properties are always enumerable.
propertyIsEnumerable property does not consider objects in the prototype chain.