Skip to content

Instantly share code, notes, and snippets.

@davidfurlong
Created April 17, 2017 07:34
Show Gist options
  • Save davidfurlong/3bdead8efa7e3506efa33b376fd68385 to your computer and use it in GitHub Desktop.
Save davidfurlong/3bdead8efa7e3506efa33b376fd68385 to your computer and use it in GitHub Desktop.
Conditional js property
const _ = (obj, cond = (val) => typeof val === 'undefined' || val === null) =>
Object.assign({},
...(Object.keys(obj).map(key =>
cond(obj[key]) ? {} : {
[key]: obj[key]
})
)
);
/*
var d;
_({d, a: null, c: 10, d: false})
===
Outputs =>
===
Object {d: false, c: 10}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment