How to check if a characters exist in a string with JavaScript

1 Answer

0 votes
s = "javascript"; 
         
document.write(s.indexOf('k') + "<br />");   

document.write(s.indexOf('s') + "<br />");    
         
if (s.indexOf('k') !== -1) {
    document.write("exist");
}
else {
    document.write("not exist");
}
 
 
 
     
/*
run:
 
-1
4
not exist 
          
*/

 



answered Jan 12, 2020 by avibootz
...