Tuesday, June 23, 2015

javascript check existence of nested object

Often, when you use a.b.c.value... the browser reports "Uncaught TypeError: Cannot read property 'value' of undefined"

It is because b does not have property c or c is undefined. It sucks if I need check if b is defined, then check if c is defined...

http://stackoverflow.com/questions/2631001/javascript-test-for-existence-of-nested-object-key

Here is my solution
http://jsfiddle.net/hairinwind/ne8w4g66/1/


No comments:

Post a Comment