I'm having a bit of trouble figuring something out. I need to use a ternary operator to return either a value or false but it's getting the data it needs from an object containing other nested objects and I can not be sure that either of those nested objects exist.
Data structure is as follows:
data = {
"foo":{
"bar": true,
"tar": true,
"rar": false
},
"goo":{
"har": true,
"par": true,
"mar": false
},
}
The ternary operator needs to basically do something like the following:
var something = data.foo.bar ? data.foo.bar : false
But it's possible that data.foo doesn't exist and also possible that data.foo.bar doesn't exist.
How can I make a check on either element not existing and returning false if either doesn't exist and returning the actual value if it does?
I don't believe this is a duplicate of the one it was marked as a duplicate of as I specifically need it to be a ternary operator. Ifs are not suitable to my purpose.