How to check if string contains a substring in TypeScript

2 Answers

0 votes
const str = "typescrip java php c c++";
const substring = "c++";
 
console.log(str.includes(substring)); 
  
      
      
      
/*
run:
      
true
 
*/

 



answered Jun 25, 2022 by avibootz
0 votes
const str = "typescrip java php c c++";
const substring = "c++";
 
console.log(str.indexOf(substring) !== -1); 
  
      
      
      
/*
run:
      
true
 
*/

 



answered Jun 25, 2022 by avibootz
...