Skip to content

Instantly share code, notes, and snippets.

@afaquejam
Last active August 18, 2019 15:34
Show Gist options
  • Save afaquejam/d7b255148cb27ce68da45415f179374f to your computer and use it in GitHub Desktop.
Save afaquejam/d7b255148cb27ce68da45415f179374f to your computer and use it in GitHub Desktop.
Javascript for iteration
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