I have this code, that works:
function getSomeValue(property) {
var obj = {
lvl1: {
lvl2: {
lvl3: 'hi'
}
}
};
//Is it ok to use eval?
return eval('obj.' + property);
}
//I would like to return the value of obj.lvl1.lvl2.lvl3
getSomeValue("lvl1.lvl2.lvl3");
It is the first time I feel the need to use eval. Is eval evil? Is there another quick way to achieve this?