Created
December 3, 2018 18:17
-
-
Save valeriocs/b33961e4e795d630f24acd4f826dc6d6 to your computer and use it in GitHub Desktop.
Easy to remove emptys from object
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
removeEmpty(object) { | |
const obj = {}; | |
// eslint-disable-next-line no-restricted-syntax | |
for (const key in object) { | |
if ( | |
object[key] !== null && | |
object[key] !== false && | |
object[key] !== undefined | |
) { | |
obj[key] = object[key]; | |
} | |
} | |
return obj; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment