Mega Code Archive

 
Categories / JavaScript Tutorial / String
 

Use indexOf method the search a substring

< html> <head> <title>Using the indexOf() method</title> <script type="text/javascript" language="javascript"> <!-- // var myString = "A ab abc abcd"; var mySubstring = "abc"; var foundAtPosition; foundAtPosition = myString.indexOf(mySubstring,0); document.write("<P>The string " + mySubstring + " was found at position " + foundAtPosition); // --> </script> </head> <body> </body> </html>