How to find the the last occurrence of a substring in a string with JavaScript

1 Answer

0 votes
let s = "c++ c php javascript golang javascript nodejs";

const pos = s.lastIndexOf("javascript");
          
if (pos !== -1)
    document.write(pos + " " + s[pos]);
else
    document.write("not found");
 
 

     
/*
run:
 
28 j 
          
*/
  

 



answered Feb 21, 2020 by avibootz
...