Created
January 12, 2023 19:02
-
-
Save AliBahaari/e73b0ed3aa483c916238259ca2e1abd7 to your computer and use it in GitHub Desktop.
Remove object properties which have `undefined` or `null` values.
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
interface IRemoveEmptyProperties { | |
[index: string]: any; | |
} | |
const removeEmptyProperties = <T extends IRemoveEmptyProperties = {}>( | |
param: T | |
) => { | |
let newObject: IRemoveEmptyProperties = {}; | |
Object.keys(param).forEach((key: any) => { | |
if (param[key]) { | |
newObject[key] = param[key]; | |
} | |
}); | |
return newObject; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment