Created
August 3, 2017 11:16
-
-
Save UplandsDynamic/8210e210f3cfab0200450db5a91c5ccc to your computer and use it in GitHub Desktop.
Javascript (Typescript): Remove empty properties from object
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
deleteEmptyProps(obj: any): any { | |
// modifies passed obj in place, removing empty properties (inc. empty arrays) | |
return Object.keys(obj).forEach(k => { | |
if (!obj[k] || obj[k] === undefined || | |
Array.isArray(obj[k]) && obj[k].length === 0) { | |
delete obj[k]; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment