If there is a Javascript object with multiple levels, as in:
myObject = {
a: 12,
obj11: {
obj111: 'John',
b:13,
obj1111: { a:15, b: 35 }
},
obj21: {
a:15,
b:16 }
}
I want to write a function to which is passed the object and an array of keys. The function should return a value based upon these keys. For example, passing [obj11,b] should return 13. Passing [obj11, obj1111,a] should return 15. Passing obj21 should return the object {a:15, b:16}
function (myObj,myArr) {
return keyVal;
}
Assuming that the keys are always correct, can anyone help me solve this problem?