Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Object JavaScript ECMAScript 6 for-of loop
// outputs elements not indices
let myArray = ['hello', 'world'];
for (let elem of myArray) {
console.log(elem);
}
/* output is
hello
world
*/
// in ECMAScript 6
// using the same array
for( let [index, elem] of myArray.entities()) {
console.log(index, elem);
}
/* output is
0 hello
1 world
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment