Before any one sais Object.keys
, that may not work here. Please read on before voting to close or commenting.
Consider the following object and the value being passed in:
As you can see I have a key, which doesn't exist in this object. But the intention is that the key being passed in might exist some where in this object and if it does I want to return the value of the hide
.
So an example would be something like:
// Pseudo code, `object` is the object in the screen shot.
if (object.hasKey('date_of_visit')) {
return object.find('date_of_visit').hide
}
Everything I have ever found on stack and the webs is "find the key by the value." I do not have the value, I just have a potential key. I have looked at lodash and underscore and a bunch of stack questions but have found nothing.
Any ideas or help would be greatly appreciated. The object nesting should not matter. If I passed in other_cause_of_death
I should get back true
.
Thoughts?
Edit:
const object = {
status: {
cause_of_death: {
hide: true,
other_cause_of_death: {
hide: true
}
}
}
};
Heres a simplified version of the object. Same rules should still apply.