Skip to content

Instantly share code, notes, and snippets.

@j6s
Created March 16, 2016 11:35
Show Gist options
  • Save j6s/28267230f7e9a00e7b88 to your computer and use it in GitHub Desktop.
Save j6s/28267230f7e9a00e7b88 to your computer and use it in GitHub Desktop.
var arr = [1,2,3];
// for length: the classic version
for (var i = 0; i < arr.length; i++) {
console.log(arr[i]);
}
// for of: simpler version of for length
for (var element of arr) {
console.log(element);
}
// for in (never use this) - iterates all available keys
// might also iterate over prototype functions
for (var element in arr) {
console.log(element);
}
// prototypal function that opens a new scope for every
// iteration
arr.forEach(function(element) {
console.log(element);
});
// someone fucked up Array#forEach
arr.every(function(element) {
console.log(element);
});
// wat
arr.some(function(element) {
console.log(element);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment