How to get the index of the last occurrence of a word in string in Node.js

1 Answer

0 votes
const str = "node.js c++ php node.js c# node.js python";
  
const wordtofind = "node.js";

const index = str.lastIndexOf(wordtofind);
  
console.log(index);
 
  
  
  
  
/*
  
run:
  
27
  
*/

 



answered Jun 7, 2022 by avibootz
...