运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!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> </html>