Last active
August 4, 2022 06:32
-
-
Save sethdavis512/3403b9f34ee0caf1e9d332cdea640249 to your computer and use it in GitHub Desktop.
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
// From https://stackoverflow.com/questions/286141/remove-blank-attributes-from-an-object-in-javascript | |
const removeEmpty = (obj) => { | |
return Object.keys(obj) | |
.filter(k => obj[k] !== null && obj[k] !== undefined && obj[k] !== '') | |
.reduce((newObj, k) => { | |
return typeof obj[k] === 'object' ? | |
Object.assign(newObj, {[k]: removeEmpty(obj[k])}) : // Recurse. | |
Object.assign(newObj, {[k]: obj[k]}); // Copy value. | |
}, {}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment