How to check if string contains a substring in Node.js

2 Answers

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

 



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

 



answered Jun 25, 2022 by avibootz
...