Created
April 23, 2019 12:34
-
-
Save 4skinSkywalker/7faa14658d9229c062957f16c2e54019 to your computer and use it in GitHub Desktop.
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
Object.prototype[Symbol.iterator] = function* () { | |
for (const key of Object.keys(this)) { | |
yield this[key] | |
} | |
} | |
var obj = { | |
'mark': 32, | |
'alex': 19, | |
'mary': 25 | |
} | |
console.log('can iterate keys') | |
for (let key in obj) { | |
console.log('key:', key) | |
} | |
console.log('can iterate values') | |
for (let value of obj) { | |
console.log('value:', value) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment