Skip to content

Instantly share code, notes, and snippets.

@LexVocoder
Created August 29, 2019 13:58

Revisions

  1. LexVocoder created this gist Aug 29, 2019.
    10 changes: 10 additions & 0 deletions cloneThenDeleteNullValues.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@

    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;
    }