Search-2

 

JavaScript search function will return 2 if you search love from a string like ""i love learnkode"

 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <button onclick="findString()">Find the position</button> <p id="sample"></p> <script> function findString() { var str = "i love learnkode"; var result = str.search(/love/i); document.getElementById("sample").innerHTML = result; } </script> </body> </html>
Output