Skip to content

Instantly share code, notes, and snippets.

@saipraveen-a
Created September 19, 2020 13:29
Show Gist options
  • Save saipraveen-a/54aaae74d92add3dd2e0a06baa90385a to your computer and use it in GitHub Desktop.
Save saipraveen-a/54aaae74d92add3dd2e0a06baa90385a to your computer and use it in GitHub Desktop.
JavaScript Understanding the Weird Parts - Array for in
const names = ['John', 'Jane', 'Joe']
for (let key in names) {
console.log(key + ": " + names[key]); // array is an object with the key being the index
}
Array.prototype.someNewProperty = 'abc';
// now we get the new property someNewProperty in the output as well.
for (let key in names) {
console.log(key + ": " + names[key]);
}
// The for of syntax available in ES6 fixes this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment