Skip to content

Instantly share code, notes, and snippets.

@hoto
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoto/8d2dbe347405beb54d17 to your computer and use it in GitHub Desktop.
Save hoto/8d2dbe347405beb54d17 to your computer and use it in GitHub Desktop.
Iterating over object literals in javascript using for in
var objectLiteral = {
name: 'bilbo',
surname: 'bagins'
};
for(var key in objectLiteral){
if(objectLiteral.hasOwnProperty(key)){
console.log('key: ' + key);
console.log('value: ' + objectLiteral[key]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment