Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Find the Position of Substring within a String</title> </head> <body> <script> var str = "If the facts don't fit the theory, change the facts."; var pos = str.indexOf("facts"); document.write(pos); // 0utputs: 7 </script> </body> </html>