Not to say it's better, but ...
x = null try { x = obj.prop.otherprop.another; } catch() {}
Or alternatively ...
function resolve(obj, path) { path = path.split('.'); while (path.length && obj) obj = obj[path.shift()]; return obj; } x = resolve(obj, 'prop.otherprop.another');
... but I think the actual answer is that there is no best practice for this. Not that I knew.
source share