javascript - How to remove undefined and null values from an object using lodash? -
i have javascript object like:
var my_object = { a:undefined, b:2, c:4, d:undefined };
how remove undefined properties?
if want remove falsey values compact way is:
_.pick(obj, _.identity);
for example (lodash 3.x):
_.pick({ a: null, b: 1, c: undefined }, _.identity); >> object {b: 1}
for lodash 4.x:
_.pickby({ a: null, b: 1, c: undefined }, _.identity); >> object {b: 1}
Comments
Post a Comment