You can, although evil, use eval after connecting all the elements of the array. i.e.
var arr = [true, '&&', false]; if(eval(arr.join(''))){
Update:
I recently thought of a very simple (no easier than eval) but safe answer. If the only logical operations you use are && and || , and parentheses are correctly formatted, you can replace regular expressions until only one value remains: "true" or "false".
Booleans for AND operations can only be as follows, and they simplify either true or false
true && true == true true && false == false false && true == false false && false == false
the same thing happens for OR operations
true || true == true true || false == true false || true == true false || false == false
As a result, we can replace the expression with our simplified values โโ- true or false. Then, if there are parentheses around the expression, they will be either '(true)' or '(false)' , and we can also easily replace that expression.
Then we can loop this procedure until we are left with one value: 'true' or 'false' .
i.e. in code
var boolArr = ["(", true, "&&", "(", false, "||", true, ")", ")", "||", true]; //Convert the array to a string "(true&&(false||true))||true" var boolString = boolArr.join(''); //Loop while the boolean string isn't either "true" or "false" while(!(boolString == "true" || boolString == "false")){ //Replace all AND operations with their simpler versions boolString = boolString.replace(/true&&true/g,'true').replace(/true&&false/g,'false'); boolString = boolString.replace(/false&&true/g,'false').replace(/false&&false/g,'false'); //Replace all OR operations with their simpler versions boolString = boolString.replace(/true\|\|true/g,'true').replace(/true\|\|false/g,'true'); boolString = boolString.replace(/false\|\|true/g,'true').replace(/false\|\|false/g,'false'); //Replace '(true)' and '(false)' with 'true' and 'false' respectively boolString = boolString.replace(/\(true\)/g,'true').replace(/\(false\)/g,'false'); } //Since the final value is a string of "true" or "false", we must convert it to a boolean value = (boolString == "true"?true:false);
Annd, if you are really dangerous, you can tie all these replacements together
Also, pay attention to the wonderful lack of recursion and using only one loop