Created
October 14, 2016 11:21
-
-
Save ardeshireshghi/8170beb64d2fe6d585116a5171948731 to your computer and use it in GitHub Desktop.
Deep check if an object has a key
This file contains 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
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