IndexOf-1

 

JavaScript indexOf function will return index of specified searched string, it will return the position else it returns -1. See the code snippet:

 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <button onclick="findPosition()">Find the position of string</button> <p id="sample"></p> <script> function findPosition() { var str = "Hello world, welcome to learnKode."; var n = str.indexOf("welcome"); document.getElementById("sample").innerHTML = n; } </script> </body> </html>
Output