Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript Strings</h1> <h2>The indexOf() Method</h2> <p>Both indexOf() and lastIndexOf() return -1 if the text is not found:</p> <p id="demo"></p> <script> let text = "Please locate where 'locate' occurs!"; let index = text.indexOf("John"); document.getElementById("demo").innerHTML = index; </script> </body> </html>