Home > DeveloperSection > Forums > If or - shorter way
Samuel Fernandes
Samuel Fernandes

Total Post:156

Points:1096
Posted on    June-06-2013 2:44 AM

 JavaScript JavaScript 
Ratings:


 1 Reply(s)
 959  View(s)
Rate this:
Hi Everyone,

I have many or inside if

if (n==0 || n==1 || n==2 || n==37 || n==5 ...)  
Is there a shorter way, something like

if (n==(0,1,2,37,5...)) 

Thanks in advance. 


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    June-06-2013 8:26 AM

Hi,

You can try as following

if([0,1,2,37,5].indexOf(n) != -1)

I hope it helpful for you.


Don't want to miss updates? Please click the below button!

Follow MindStick