I have a situation similar with the one here: Javascript check if object property exists, even when object is undefined.
My problem is, what happens if you have a chain of properties. Example:
var obj = {'a': {'b': {'c': {'d': 'I exists'}}}}
I need to check if 'd' is defined. In order to not get an error, I would have to check like:
if (typeof obj != 'undefined' && typeof obj['a'] != 'undefined' && typeof obj['a']['b'] != 'undefined' && typeof obj['a']['b']['c'] != 'undefined' && typeof obj['a']['b']['c']['d'] != 'undefined')
You can see how this can get annoying. Extrapolate to a level 999 deep element for example. Is there any way to get rid of the first n-1 conditions?
obj.a.b.c.d !== 'undefined'statement with atry ... catchblock. Like this example.