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> let str = "If the facts don't fit the theory, change the facts."; let pos = str.indexOf("facts"); document.write(pos); // 0utputs: 7 </script> </body> </html>