Created
September 19, 2020 13:29
-
-
Save saipraveen-a/54aaae74d92add3dd2e0a06baa90385a to your computer and use it in GitHub Desktop.
JavaScript Understanding the Weird Parts - Array for in
This file contains hidden or 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
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