Champion: Dave Herman
Details: ES6 draft section 12.6.4
for-of loop is for looping over iterable objects.
for (let word of ["one", "two", "three"]) alert(word); let s = new Set([3, 4, 5]); for (let value of s) alert(value); let m = new Map([['red', 'rojo'], ['blue', 'azul']]); for (let [name, value] of m) alert(name + " = " + value);
for-of is also available in array comprehensions.
See iterators for examples of how to create custom iterable objects.
How for-of is different from for-in
for-in loops look similar, but they do two very different things.
for-inis for inspecting object properties. It works on any object, and it always loops over the names of the object's enumerable properties.
for-ofis for looping over data. It only works on iterable objects; that is, objects with a suitable
var colors = new Set(['rojo', 'amarillo', 'azul']); colors.language = 'es'; // add an expando property for (let name in colors) alert(name); // "language" (the property name) for (let word of colors) alert(word); // "rojo", "amarillo", "azul" (the data)