String.indexOf() (Method)

The location of a sub-string within a string.


ECMAScript edition - 2
JavaScript - 1.0
JScript - 1.0
Internet Explorer - 3.02
Netscape - 2.0
Netscape Enterprise server - 2.0
Opera - 3.0
Property/method value type:Number primitive
JavaScript syntax:-myString.indexOf(aSearchString)
-myString.indexOf(aSearchString, aPosition)
Argument list:aPositionAn optional valid character position within the string to indicate the search start
aSearchStringA 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.

Example code:

   myIndex = myString.indexOf("MN");

See also:String.prototype


ECMA 262 edition 2 - section -

ECMA 262 edition 3 - section -