Last active
March 11, 2016 14:14
-
-
Save jisaacks/c62547c5d83e00af270e to your computer and use it in GitHub Desktop.
Iterate key/vals of Objects
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
function* keyValIterator (obj) { | |
for (let prop in obj) { | |
yield [ prop, obj[prop] ]; | |
} | |
} | |
var address = { | |
street: '420 Paper St.', | |
city: 'Wilmington', | |
state: 'Delaware' | |
}; | |
for (let [ key, val ] of keyValIterator(address)) { | |
console.log(key, val); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment