- https://stackoverflow.com/questions/6491463/accessing-nested-javascript-objects-with-string-key
- https://stackoverflow.com/questions/8051975/access-object-child-properties-using-a-dot-notation-string
1
2
3
4
5
6
7
8function getDescendantProp(obj, desc) {
var arr = desc.split(".");
while(arr.length && (obj = obj[arr.shift()]));
return obj;
}
console.log(getDescendantProp(r, "b.b2"));
//-> 99