Easy way to get multi-level javascript object property
I always need to deal with multi-level js objects where existence of
properties are not certain:
try { value1 = obj.a.b.c; } catch(e) { value1 = 1; }
try { value2 = obj.d.e.f; } catch(e) { value2 = 2; }
......
Is there an easier way or a generic function (e.g. ifnull(obj.d.e.f, 2) )
that does not require a lot of try catches?
No comments:
Post a Comment