Skip to content

Instantly share code, notes, and snippets.

@laran
Last active October 31, 2018 16:59
Show Gist options
  • Save laran/185a861f61df529fdfb4bb77f7de549f to your computer and use it in GitHub Desktop.
Save laran/185a861f61df529fdfb4bb77f7de549f to your computer and use it in GitHub Desktop.
Iterate elements in list
let list = [ 'val1', 'val2' ];
// Least nice
for(let i = 0; i < list.length; i++) {
console.log(list[i]);
}
// Nicer
list.forEach((element) => {
console.log(element);
});
// Nicest
for(element of list) {
console.log(element);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment