Skip to content

Instantly share code, notes, and snippets.

@indreklasn
Last active January 15, 2020 13:01
Show Gist options
  • Save indreklasn/9b63126b249101c334d23637110454be to your computer and use it in GitHub Desktop.
Save indreklasn/9b63126b249101c334d23637110454be to your computer and use it in GitHub Desktop.
const dogs = {
name: "Sam",
age: 10,
}
// Looping over objects
for (let prop in dogs) {
console.log(prop); // "name", "age"
}
Object.keys(dogs).forEach(key => {
console.log(`${key} : ${dogs[key]}`);
// "name : Sam"
// "age : 10"
});
Object.values(dogs).forEach(value => console.log(value)); // "Sam", 10
Object.entries(dogs).forEach(([key, value])=>{
console.log(`${key}:${value}`)
//"name:Sam"
//"age:10"
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment