This is my code snippet
pastActions = res['data']['list']['names']['blk'].cnt
But I get to see below error
its throws error as Cannot read property 'cnt' of undefined
This is because the parent of cnt
is undefined, it might even fail when any of these properties data
or list
or names
or blk
is undefined.
I have replaced it as below
res['data'] && res['data']['list] && res['data']['list']['names'] && res['data']['list']['names']['blk'] && res['data']['list']['names']['blk'].cnt ? res['data']['list']['names']['blk'].cnt : '';
and it works, but is there any optimized way to check the same?