I am blacking out over issue and I am convinced I am thinking too complex about this, but summarized, my issue is about this:
// imagine this variable is dynamically filled by a loop with conditions inside
var condition = varA + " == " + varB + " && " + varC + " == " + varD;
if (condition) {
// something
}
So it doesn't check whether varA equals varB and varC equals varD as what I intended, but instead it just sees it as a string and that appears to be always true anyway. I don't want, I want to see it actually checking whether varA equals varB etc.
Is there a way to parse this statement into something that actually can be a 'legit' if condition?
Thanks!
eval()but it's generally frowned upon. still why not just write that if statement? it doesn't really make sense to build it this wayrunningBool = runningBool && varX == varY. At the end of the loop,runningBoolwill be true or false.if (varA == varB && ...)would normally work as well indeed, but that won't help in my situation as in this if-statement the amount of conditions varies per case. It could be that the conditionvarA == varBis omitted dynamically through filtering so onlyvarC == carDremains. Case is too that every (dynamically added) condition needs to be true. I wonder if this is the way to go to accomplish this anyway, so it's the question how else I would be able to do this.eval()but why not just use a switch statement and handle the amount of variables with separate cases?