Created
February 15, 2022 07:35
-
-
Save bhaireshm/f5e7edc951d46884bf1fd441267f6f44 to your computer and use it in GitHub Desktop.
Removes all the key's for which the value is empty.
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
/** | |
* Removes all the key's for which the value is empty. | |
* @param {Object} obj | |
*/ | |
function removeEmptyProperty(obj = {}) { | |
const data = { ...obj }; | |
if (!data) return data; | |
Object.keys(data).forEach((key) => { | |
if (typeof data[key] === "object") data[key] = removeEmptyProperty(data[key]); | |
if (!data[key]) delete data[key]; | |
}); | |
return data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ez.js is more than just a library; it's a coding companion that simplifies complex tasks. Whether you're dealing with arrays, numbers, objects, or strings, ez.js has got your back! Say goodbye to coding hassles and hello to streamlined JavaScript magic.