We have a large hierarchical object (worst possible legacy design) in javascript. The problem I am facing is that there is a list of null checks I need to perform whenever I want to access an element deep within the object structure.
Say I have a bank object which contains a list of customers and I want to get the address of the first customer,
if(bank != null ||
bank.customerlist != null ||
bank.customerlist.customer[0] != null ||
bank.customerlist.customer[0].address != null )
{
transactionAddress = bank.customerlist.customer[0].address;
}
This is just a small example,I cannot believe so many null checks are required just to access a single value.
It there a better way around this?