I need to convert variables from the format variableName[field1][field2] to variableName.field1.field2
This conversion is necessary because users can input variable names in the user interface, and I want to avoid using eval() directly. Instead, I have implemented a function for this purpose:
function getDescendantProp(obj, desc) {
var arr = desc.split(".");
while (arr.length) {
obj = obj[arr.shift()];
}
return obj;
}
Using this function allows me to retrieve the value of the variable without executing code at runtime. However, it does not support variables specified within square brackets [ ].