Created
March 16, 2016 11:35
-
-
Save j6s/28267230f7e9a00e7b88 to your computer and use it in GitHub Desktop.
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
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