运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript Strings</h1> <h2>The lastIndexOf() Method</h2> <p>The lastIndexOf() method accepts a second parameter as the starting position for the search.</p> <p>Remember that the lastIndexOf() method searches backwards, so position 15 means start the search at position 15, and search to the beginning.</p> <p id="demo"></p> <script> let text = "Please locate where 'locate' occurs!"; let index = text.lastIndexOf("locate", 15); document.getElementById("demo").innerHTML = index; </script> </body> </html>