Created
October 2, 2017 20:11
-
-
Save KimSarabia/2c25384807fee9ff280a71d99247e772 to your computer and use it in GitHub Desktop.
Iterate over the properties of an object
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
//Use For-In | |
var buz = { | |
fog: 'stack' | |
}; | |
for (var name in buz) { | |
if (buz.hasOwnProperty(name)) { | |
console.log('this is fog (' + | |
name + ') for sure. Value: ' + buz[name]); | |
} | |
else { | |
console.log(name); // toString or something else | |
} | |
} | |
//console: this is fog (fog) for sure. Value: stack |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment