Skip to content

Instantly share code, notes, and snippets.

@timoweiss
Last active August 29, 2015 13:59
Show Gist options
  • Save timoweiss/10714191 to your computer and use it in GitHub Desktop.
Save timoweiss/10714191 to your computer and use it in GitHub Desktop.
~ tilde shortcut | is it in the array?
//~ 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