Skip to content

Instantly share code, notes, and snippets.

@devdays
Created December 10, 2014 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devdays/20bb80b9a8608d961ed1 to your computer and use it in GitHub Desktop.
Save devdays/20bb80b9a8608d961ed1 to your computer and use it in GitHub Desktop.
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