Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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