If I a reference to an object -
var test = {};
that will potentially (but not immediately) have nested objects, something like -
{ level1:{level2:{level3:'level3'}} };
what is the best way to test for the existence of keys in the most deeply nested objects?
This -
alert(test.level1);
returns 'undefined', but this -
alert(test.level1.level2.level3);
fails.
I'm currently doing something like this -
if(test.level1 && test.level1.level2 && test.level1.level2.level3) {
alert(test.level1.level2.level3);
}
but I was wondering if there's a better way.
Thanks much.