My question was going to be how to do this at all but I came across eval which seems to work. I’m told eval is evil and the explanations for why went way over my head so my question is:
Is there anything wrong with using eval like this, or other ways to do it at all?
var condition1=false;
var condition2=true;
var condition3=false;
//etc
if (condition1){x = "1"}
else if (condition2){x = "2"}
else if (condition3){x = "3"};
//etc
var thing1= 11;
var thing2= 22;
var thing3= 33;
//etc
eval ("thing" + x)
Probably the best solution would be to replace all of those variables with an array:
then you can just do :
If the variables are global, you could also do this:
But ideally you would not want these to be global.