LastIndexOf-1

 

JavaScript lastIndexOf() function returns the last index of specified string from string. See the code snippet:

 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <p>Click the button to locate the last occurance of a specified value.</p> <button onclick="lastOccurance()">Find the position of string</button> <p id="sample"></p> <script> function lastOccurance() { var str = "I like learnkode and i love learnkode."; var n = str.lastIndexOf("learnkode"); document.getElementById("sample").innerHTML = n; } </script> </body> </html>
Output