In case someone was wondering how to access sub properties (dynamically), I have found a way for that, if there's an easier way, please let me know:
function getPropertyByKeyPath(targetObj, keyPath) {
var keys = keyPath.split('.');
if(keys.length == 0) return undefined;
keys = keys.reverse();
var subObject = targetObj;
while(keys.length) {
var k = keys.pop();
if(!subObject.hasOwnProperty(k)) {
return undefined;
} else {
subObject = subObject[k];
}
}
return subObject;
}
For example this:
var o = {result : {info:{ version:1, comment: 'test'}}};
var subObject = getPropertyByKeyPath(o, 'result.info');
console.log(subObject);
would result in:
{version: 1, comment: "test"}