Name
indexOf() — NN 2 IE J1 ECMA 1
Synopsis
indexOf(searchString[,startPositionIndex])
Returns a zero-based integer of the position within the current
string where the searchString parameter
starts. Normally, the search starts with the first (index of zero)
character, but you may have the search begin later in the string by
specifying the optional second parameter, which is the index value of
where the search should start. If there is no match, the returned
value is -1. This is a backward-compatible quick
way to find out if one string contains another: If the returned value
is -1 then you know the
searchString is not in the larger string.
If the returned value is another number (the precise value
doesn’t matter), the searchString is
in the larger string. For Version 4 browsers, the
String object’s search()
method performs a similar function.
Returned Value
Integer.
Parameters
-
searchString A string to look for in the current string object
-
startPositionIndex A zero-based integer indicating the position within the current string object to begin the search of the first parameter
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access