Created
November 26, 2013 02:12
-
-
Save nola/7652479 to your computer and use it in GitHub Desktop.
Shorter IF’z
If you have multiple IF variable value comparisons you can simply ass them to an array and check for presence. You could use $.inArray as an alternative.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if( myvar==1 || myvar==5 || myvar==7 || myvar==22 ) alert('yeah') | |
| //shorthand | |
| if([1,5,7,22].indexOf(myvar)!=-1) alert('yeah baby!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment