Last active
August 29, 2015 13:59
-
-
Save timoweiss/10714191 to your computer and use it in GitHub Desktop.
~ tilde shortcut | is it in the array?
This file contains 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
//~ is a bitwise NOT operator, which will return 0 only for -1. | |
// check http://stackoverflow.com/questions/18347033/how-to-shorten-my-conditional-statements/18347047#answer-18347047 | |
var test = { type: 3 }; | |
if ( ~[1, 2, 3, 4].indexOf(test.type) ) { | |
alert('woohooo!'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment