Skip to content

Instantly share code, notes, and snippets.

@bhaireshm
Created February 15, 2022 07:35
Show Gist options
  • Save bhaireshm/f5e7edc951d46884bf1fd441267f6f44 to your computer and use it in GitHub Desktop.
Save bhaireshm/f5e7edc951d46884bf1fd441267f6f44 to your computer and use it in GitHub Desktop.
Removes all the key's for which the value is empty.
/**
* 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;
}
@bhaireshm
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment