Created
September 14, 2021 12:50
-
-
Save fedek6/ea45e1d5b34cd80226fa4939d41cbab2 to your computer and use it in GitHub Desktop.
Flatten object literal with other objects (without knowing property names)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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