Last active
June 22, 2018 03:46
-
-
Save majidzeno/22b865eb8a6b460d8c61f9a2d6cc85c4 to your computer and use it in GitHub Desktop.
Using the "~" with "indexOf" function
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
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