q1 = {
qTxt: "I want this text to be displayed in the alert box.",
usedBefore: true
};
var foo = "q1"
alert(eval(foo).qTxt);
While searching other answers on StackOverflow, I found a solution to my problem which uses eval(). But I did read before that eval() is bad (eval is evil) and it shouldn't be used.
If it really is a bad to use it, how could I get the same result.
I heard of something like alert(member['foo']), but when I tried to use it, it didn't work: alert(['foo']qTxt);
EDIT: I didn't get an answer for my problem from the "duplicate". That question only shows how to change the parameter, but I'm trying to change the first part (q1) which seems to be not working for me.
EDIT 2: My code.
q1 = {
qTxt: "The answer is true.",
usedBefore: false
};
var foo = "q1";
alert([foo].qTxt); // without the dot, an error comes up