How to use indexOf to get the index of the first substring in a string in JavaScript

2 Answers

0 votes
const str = 'javascritp php java php';

let pos = str.indexOf('php');
  
console.log(pos); 
 
   
    
/*
run:
     
11
        
*/

 



answered Aug 31, 2019 by avibootz
edited Aug 29, 2020 by avibootz
0 votes
const str = 'javascritp php java';

let pos = str.indexOf('java');
  
console.log(pos); 
 
   
    
/*
run:
     
0
        
*/

 



answered Aug 31, 2019 by avibootz
edited Aug 29, 2020 by avibootz
...