I often write this repetitive code:
if (SERVER_ENV == "TEST" || SERVER_ENV == "PROD" || SERVER_ENV == "QA") {
// ...
}
Is there a better way to write conditional checks like this in Javascript? When you need to check against more than one pre-defined value.
I mean, I could do:
const POSSIBLE_ENVS = ["TEST","PROD","QA"];
if (POSSIBLE_ENVS.includes(SERVER_ENV))
// OR
if (POSSIBLE_ENVS.indexOf(SERVER_ENV) >= 0)
But that is cumbersome and it inverts my logical thinking. I'm writing does that array contain my value ?
instead of is my value inside that array ?
How to people usually handle this? Is there a ECMA proposal or any other syntactical sugar available?