String.indexOf

Returns the index within the calling String object of the first occurrence of the specified value, starting the search at fromIndex, or -1 if the value is not found.

Method of String

Syntax

indexOf( searchValue[, fromIndex] )

Parameters

Parameter Description
searchValue A string representing the value to search for.
fromIndex The location within the calling string to start the search from. It can be any integer between 0 and the length of the string. The default value is 0.

Description

Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character of a string called stringName is stringName.length - 1.

The indexOf method is case sensitive. For example, the following expression returns -1:

See also

String.charAt, String.lastIndexOf, String.split

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.