How to check if string contains a substring in JavaScript

2 Answers

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

 



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

 



answered May 28, 2021 by avibootz
edited Jun 25, 2022 by avibootz
...