Skip to content

Instantly share code, notes, and snippets.

@linktohack
Last active November 29, 2017 10:07
Show Gist options
  • Save linktohack/6973ba050139f55b0ba588b4779d88aa to your computer and use it in GitHub Desktop.
Save linktohack/6973ba050139f55b0ba588b4779d88aa to your computer and use it in GitHub Desktop.
Without null
function withoutNull(object) {
object = _.omitBy(object, _.isNull);
_.forEach(object, function (val, key) {
if (_.isObject(object[key])) {
object[key] = withoutNull(val)
}
if (_.isArray(val)) {
object[key] = _.map(val, withoutNull)
}
});
return object;
}
function withoutEmpty(object) {
_.forEach(object, function (val, key) {
if (_.isObject(object[key])) {
object[key] = withoutEmpty(val)
}
if (_.isArray(val)) {
object[key] = _.map(val, withoutEmpty)
}
});
object = _.omitBy(object, function(val) {
return _.isNull(val) || (_.isEmpty(val) && (_.isArray(val) || _.isObject(val)));
});
return object;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment