Last active
August 18, 2019 15:34
-
-
Save afaquejam/d7b255148cb27ce68da45415f179374f to your computer and use it in GitHub Desktop.
Javascript for iteration
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 myArray = [1, 2, 3, 4]; | |
// This iterates over contents of container. This is not applicable for objects. | |
for (item of myArray) { | |
console.log(item); // 1, 2, 3, 4 | |
} | |
let myObject = { | |
first: 1, | |
second: 2 | |
}; | |
// This can only be used in objects. | |
for (item in myObject) { | |
console.log(`${item} => ${myObject[item]}`); // first => 1, second => 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment