You can use this function:
function get_property_from_target(obj, target){ var arr = target.split('.'); for(var i = 0; i < arr.length; i++){ if(obj) obj = obj[arr[i]]; } return obj; }
Then name it like this:
get_property_from_target(myObject, target);
I would rename the function to something better.
Also, do not name the property of var objects, since this is a keyword in Javascript, this can be confusing, and I'm not sure if it will always work the way you expect, or if it just causes errors in some browsers.
source share