Skip to content

Instantly share code, notes, and snippets.

@LexVocoder
Created August 29, 2019 13:58
Show Gist options
  • Save LexVocoder/dc3bd07142391202b6e13a14655f81b2 to your computer and use it in GitHub Desktop.
Save LexVocoder/dc3bd07142391202b6e13a14655f81b2 to your computer and use it in GitHub Desktop.
function cloneThenDeleteNullValues(obj: object) {
const res = Object.entries(obj).reduce((acc: object, [k, v]) => {
if (typeof v !== 'undefined' && v != null) {
acc[k] = v;
}
return acc;
}, {} as object);
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment