[Solved] Javascript multiple OR in statement [duplicate]


What you’re actually looking for is a logical AND, which would ensure that every condition is met:

if (bedroomNums != "0_0" && bedroomNums != "0_1" && bedroomNums != "0_2") {
    // `bedroomNums` is not one of "0_0", "0_1", "0_2"
}

If one of these checks returns FALSE (that is, bedroomNums is set to one of these values), the code inside the curly braces will not be executed.


An alternative way to express this same condition would be to enumerate each of these values you’re comparing against into an Array structure, then checking to ensure that the value of bedroomNums isn’t present in said Array using Array.prototype.includes():

if (!["0_0", "0_1", "0_2"].includes(bedroomNums)) {
    // `bedroomNums` is not one of "0_0", "0_1", "0_2"
}

This style is generally more helpful in situations where your program has to enumerate all possible values for a condition dynamically (based on some other logic or data source).

solved Javascript multiple OR in statement [duplicate]