I’ve run into a block… I need to retrieve the value of a variable, but I need to dynamically get the value of the variable.
Take this for example.
var mMenu1 = “Menu 1”;
var mMenu2 = “Menu 2”;
var mMenu3 = “Menu 3”;
var flag = true;
//Now I want to use a loop to figure out what each of the values are… Now in all reality, I won’t know what the number goes up to, so I’ll have to use a while loop…
var x = 0;
while(flag) {
x++;
//When x hits 4, eval can’t find the var and kills my code… What I really need to know is if there’s some condition I can run to check whether that var exists before running the eval statement or if the eval statement returns some “undefined” thing if the var doesn’t exist.
if (somecondition) {
mTest = eval(“mMenu”+x);
}
else {
flag = false;
}
Any help would be appreciated, thanks ?