"for each...in" iterates a specified variable over all values of the specified object's properties.
Example:
var sum = 0;
var obj = {prop1: 5, prop2: 13, prop3: 8};
for each (var item in obj) {
sum += item;
}
print(sum); // prints "26", which is 5+13+8
Source
"for...in" iterates a specified variable over all properties of an object, in arbitrary order.
Example:
function show_props(obj, objName) {
var result = "";
for (var i in obj) {
result += objName + "." + i + " = " + obj[i] + "
";
}
return result;
}
Source
Note 03.2013, for each... in
loops are deprecated. The 'new' syntax recommended by MDN is for... of
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…