IndexOf-2

 

Example of JavaScript indexOf function.

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