How to check if a character exists in a string with JavaScript

1 Answer

0 votes
s = "javascript"; 
          
console.log(s.indexOf('k'));   

console.log(s.indexOf('s'));   

console.log(s.includes('t'));   

if (s.indexOf('k') !== -1) {
    console.log("exist");
}
else {
    console.log("not exist");
}

  
      
/*
run:
  
-1
4
true
not exist
           
*/

 



answered Jan 12, 2020 by avibootz
edited 4 hours ago by avibootz
...