Skip to content

Instantly share code, notes, and snippets.

@KimSarabia
Created October 2, 2017 20:11
Show Gist options
  • Save KimSarabia/2c25384807fee9ff280a71d99247e772 to your computer and use it in GitHub Desktop.
Save KimSarabia/2c25384807fee9ff280a71d99247e772 to your computer and use it in GitHub Desktop.
Iterate over the properties of an object
//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