I have several if statements in my script which require a lot of conditions and I would like to write them in the more efficient way and with "shorthand notation" for the readability.
For example, I have this if statement:
if (x === 'a' || x === 'b' | x === 'c' || x ==='d') {
/*** some code ***/
}
So I have written it in with indexOf and array but i'm not sure if it's the best way:
if (['a', 'b', 'c' ,'d'].indexOf(x) > -1) {
/*** some code ***/
}
I'm near sure there are some other methods more cleaner and fastest...
Aucun commentaire:
Enregistrer un commentaire