Skip to content

Instantly share code, notes, and snippets.

@nikolasrangel
Created March 6, 2019 21:47
Show Gist options
  • Save nikolasrangel/f256ddabec78e19e28df32e3f8986a6d to your computer and use it in GitHub Desktop.
Save nikolasrangel/f256ddabec78e19e28df32e3f8986a6d to your computer and use it in GitHub Desktop.
mapping js objects
const cats = {
Puma: { age: 3 },
Ringo: { age: 4 }
};
const object = Object.keys(cats)
.map(cat => ({[cat]: `age: ${cats[cat].age}`}) )
.reduce((acc, curr) => ({...acc, ...curr}) , {});
/* object:
{
Puma: "age: 3"
Ringo: "age: 4"
}
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment