Skip to content

Instantly share code, notes, and snippets.

@silently
Last active November 22, 2016 09:00
Show Gist options
  • Save silently/adb078679399a5cb0424 to your computer and use it in GitHub Desktop.
Save silently/adb078679399a5cb0424 to your computer and use it in GitHub Desktop.
3 ways to iterate over arrays
var a = [1, 2, 3, 4, 5];
// standard for loop
for (let i = 0; i < a.length; i++) {
console.log(a[i]);
}
// from ES5
a.forEach(function(item) {
console.log(item);
});
// from ES6
for(let item of a) {
console.log(item);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment