Last active
October 31, 2018 16:59
-
-
Save laran/185a861f61df529fdfb4bb77f7de549f to your computer and use it in GitHub Desktop.
Iterate elements in list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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