Loops/Foreach: Difference between revisions

Line 666:
}
}</lang>
 
{{works with|JavaScript|1.6}}
;Deprecated
There is also a <tt>[https://developer.mozilla.org/en-US/Core_JavaScript_1.5_Referencedocs/Global_ObjectsJavaScript/ArrayReference/forEachStatements/for_each...in for each in]</tt> construct that iterates over the values of an object:
<lang JavaScript>h = {"one":1, "two":2, "three":3}
for (x in h) print(x);
Line 677 ⟶ 679:
 
for each (y in h) print(y);
/*
2
1
3
*/</lang>
 
{{works with|ECMAScript|6th edition}}
There is also a <tt>[https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Statements/for...of for of]</tt> construct that iterates over the values of an object:
<lang JavaScript>h = {"one":1, "two":2, "three":3}
for (x in h) print(x);
/*
two
one
three
*/
 
for (y of h) print(y);
/*
2
Anonymous user