| Availability: |
| ||||||||
| Property/method value type: | Number primitive | ||||||||
| JavaScript syntax: | - | myString.indexOf(aSearchString) | |||||||
| - | myString.indexOf(aSearchString, aPosition) | ||||||||
| Argument list: | aPosition | An optional valid character position within the string to indicate the search start | |||||||
| aSearchString | A string to search for within the String object | ||||||||
Returns a value indicating the location of the search string within the receiving String object.
If the search string is not found, the value -1 is returned.
You can indicate a starting position within the target string and if that argument is missing, the whole string will be searched. The same happens if you put the value 0 into the second parameter.
<HTML>
<HEAD>
</HEAD>
<BODY>
<SCRIPT>
myString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
myIndex = myString.indexOf("MN");
document.write(myString.substr(myIndex));
</SCRIPT>
</BODY>
</HTML>| See also: | String.prototype |
| Prev | Home | Next |
| String.fromCharCode() | Up | String.italics() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. | ||