Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Strings</h1>
<h2>The lastIndexOf() Method</h2>
<p>lastIndexOf() returns the index of the last occurrence of a specified value in a string.</p>
<p>Find the last occurence of "planet", starting at position 20:</p>
<p id="demo"></p>
<script>
let text = "Hello planet earth, you are a great planet.";
let result = text.lastIndexOf("planet", 20);
document.getElementById("demo").innerHTML = result;
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_lastindexof2 by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 05 Sep 2022 15:18:41 GMT -->
</html>