Last active
November 29, 2017 10:07
-
-
Save linktohack/6973ba050139f55b0ba588b4779d88aa to your computer and use it in GitHub Desktop.
Without null
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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