I have a a function that takes a string like "obj.key.subkey.subsubkey":
function(obj, key) {
return eval('obj.'+ key);
}
What would be a safe alternative to eval in this case or is eval fine? new Function won’t work in this case AFAIK. Maybe split and loop then?
I’m not sure you really need a function here. If you have the object and the key just use the key to return the property on the object.
If you must handle multiple keys:
Working Example: http://jsfiddle.net/H55ka/