I have several if statements in my script that require a lot of conditions, and I would like to write them in a more efficient way and with a “shorthand notation” for readability.
For example, I have an if statement:
if (x === 'abc' || x === 'def' || x === 'ghi' || x ==='jkl') {
/*** some code ***/
}
So, I wrote it using indexOf and an array, but I'm not sure if this is the best way:
if (['abc', 'def', 'ghi' ,'jkl'].indexOf(x) > -1) {
}
I am pretty sure there are other methods cleaner and faster ...
source
share