It seems that the following technique for checking the existence of an object member produces an error because the \'bar\' parent object hasn\'t been declared before the che
As Matthew Abbott gave in his response, you can write a method for it to use it later if you do a lot of diving into child properties where the whole object or somewhere along the chain can be null. Below is my implementation using lodash.
checkGraph(obj, graphPath) {
if (obj) {
let root = obj;
_.each(graphPath.split('.'), part => {
if (root[part]) {
root = root[part];
} else {
return false; // bad property
}
});
return true;
}
return false; // bad object
}
You can call the method like this:
if (this.checkGraph(object, 'property.subproperty') {
// do thing
}