Created
February 25, 2021 19:52
-
-
Save neodigm/033518afaeea181b572706678bd02760 to your computer and use it in GitHub Desktop.
Recursive Object Squash
This file contains 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
function squash(object) { // Deep JavaScript Object Squash | |
return Object | |
.entries(object) | |
.map(([key, value]) => Object.assign({ key }, value && typeof value === "object" | |
? { value: '', children: squash(value) } | |
: { value, children: [] } | |
)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment