Hussein Hussein - 3 months ago 9
Javascript Question

Shorter code for this JavaScript "if" statement

Is there a short way to write the following using either JavaScript or jQuery?

if (this.id==="a" || this.id==="b" || this.id==="c" || this.id==="d")

Answer
if ( ['a','b','c','d'].indexOf( this.id ) >= 0 ) { ... }

or

if ( this.id in {'a':0,'b':0,'c':0,'d':0} ) { ... }