Skip to content

Instantly share code, notes, and snippets.

@ardeshireshghi
Created October 14, 2016 11:21
Show Gist options
  • Save ardeshireshghi/8170beb64d2fe6d585116a5171948731 to your computer and use it in GitHub Desktop.
Save ardeshireshghi/8170beb64d2fe6d585116a5171948731 to your computer and use it in GitHub Desktop.
Deep check if an object has a key
const hasKeyDeep = ((_) => {
return (object, keyName) => {
let hasKey = false;
if (_.has(object, keyName)) {
return true;
}
_.forEach(object, (value) => {
if (_.isObject(value)) {
hasKey = hasKeyDeep(value, keyName);
// Break if found a match
if (hasKey) {
return false;
}
}
});
return hasKey;
};
})(_);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment