Skip to content

Instantly share code, notes, and snippets.

@majidzeno
Last active June 22, 2018 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save majidzeno/22b865eb8a6b460d8c61f9a2d6cc85c4 to your computer and use it in GitHub Desktop.
Save majidzeno/22b865eb8a6b460d8c61f9a2d6cc85c4 to your computer and use it in GitHub Desktop.
Using the "~" with "indexOf" function
if(~x.indexOf('a')){alert('found it ')}else{alert('bad luck mate :( ')};
use ~ instead of relying on the result of indexOf if it -1 or not to tell if this string have the search item or not
where x is a string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment