Skip to content

Instantly share code, notes, and snippets.

@fedek6
Created September 14, 2021 12:50
Show Gist options
  • Save fedek6/ea45e1d5b34cd80226fa4939d41cbab2 to your computer and use it in GitHub Desktop.
Save fedek6/ea45e1d5b34cd80226fa4939d41cbab2 to your computer and use it in GitHub Desktop.
Flatten object literal with other objects (without knowing property names)
const typography = {
primary: {
family: "Lato"
},
secondary: {
family: "Roboto"
}
};
const aliases = Object.entries(typography)
.map((o) => {
return { [o[0]]: o[1].family };
})
.reduce((v, i) => Object.assign({}, v, i));
/*
Output:
{
"primary": "Lato",
"secondary": "Roboto"
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment