konstantinbueschel
10/10/2016 - 6:47 AM

Remove empty properties falsy values from object with Underscore >= 1.7.0 or Lodash From http://stackoverflow.com/questions/14058193/remove

Remove empty properties falsy values from object with Underscore >= 1.7.0 or Lodash

From http://stackoverflow.com/questions/14058193/remove-empty-properties-falsy-values-from-object-with-underscore-js

var cleanedObj;

// Underscore >= 1.7.0
cleanedObj = _.pick(sourceObj, _.identity);

// Lodash >= 0.1.0
cleanedObj = _.pick(sourceObj, _.identity);

// Lodash >= 4.0.0
cleanedObj = _.pickBy(sourceObj);