Not sure how to word this.
I am trying to use a variable to determine how far to drill into an object to return a value.
var target = "level1.level2.var";
var myObject = {
level1: {
level2: {
var: 'value'
}
}
}
var returnVal = myObject.target;
How could this be done? Clearly this won't work. Is it possible some other way?
I figured I would have to maybe explode the target var and then loop for each level, but thought I'd ask to see if there was any easier way I could be overlooking.
returnVal = eval("myObject."+target)?eval.