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

Get Dynamic HTML: The Definitive Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.