IF OR - SHORTER WAY

Samuel Fernandes

Total Post:159

Points:1117
Posted by  Samuel Fernandes
 1279  View(s)
Ratings:
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. 
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: If or - shorter way

    Hi,


    You can try as following

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

    I hope it helpful for you.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!