Considering this example:
if(this.plantService.plants[id])
{
if(this.plantService.plants[id].Name)
{
if(this.plantService.plants[id].Name[0])
return this.plantService.plants[id].Name[0].value;
else
return '';
}
else
return '';
}
return '';
I am wondering if it is possible to simplify what I am doing here.
My goal is to test the object-chain this.plantService.plants[id].Name[0]
for validity.
However, if I just test if(this.plantService.plants[id].Name[0]) {...}
exceptions are thrown.
Any proposals? :)