I need to evaluate a variable and check if it's equal to one of two other variables.
I do it like this:
if (a == b || a == c)
{
}
I feel there's got to be a better way to evaluate variables in this manner. Is there?
You can also use Array.prototype.includes (ES7).
if ([b, c, d, e].includes(a)) {
// do stuff
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With