I'm having trouble figuring out how to access a variable in a multilevel deep object using a function like
getLanguageVariable("form.passwordSwitch.disabled");
and the following object as sample
var language = {
"de": {
"form": {
"passwordSwitch": {
"enabled": "Der Klartext-Modus ist aus. Aktivieren?",
"disabled": "Der Klartext-Modus ist an. Deaktivieren?"
}
}
}
}
Tried to split the string at the dot character, then creating a string representation of
language["de"]["form"]["passwordSwitch"]["enabled"]
which is used to access objects and it's properties. I used this code:
var stack = variableIdentifier.split(".");
var reference = "";
for (i = 0; i < stack.length; i++) {
if (i == 0) reference += stack[i];
else reference += "[\"" + stack[i] + "\"]";
}
Any clues how to dynamically access the properites of an object, given you don't know how deep it is?