Skip to content

Instantly share code, notes, and snippets.

@neodigm
Created February 25, 2021 19:52
Show Gist options
  • Save neodigm/033518afaeea181b572706678bd02760 to your computer and use it in GitHub Desktop.
Save neodigm/033518afaeea181b572706678bd02760 to your computer and use it in GitHub Desktop.
Recursive Object Squash
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