Is there a way to test for occurrence of specific characters in a more elegant way using Javascript syntax but without RegEx? Trying to avoid repetitive 'or' conditions if possible.
if (target == "+" || target == "-" || target == "*" || target == "/") {
alert("hit a function");
}
Thanks.
There are a couple of ways of doing this:
includes: ['+', '-', '*', '/'].includes(target) const values = { '*': true, '-': true, '+': true, '/': true}
if (values[target] === true)
But writing a long boolean condition could also work. Just wrap that in a function so you don't have to c/p code around