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

1 Answer

0 votes
let s: string = "typescript";

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 12 hours ago by avibootz
...