String.prototype.indexOf

Returns the index of the first occurrence of a substring in the string.

Syntax

indexOf(substring, startIndex?)

Parameters

Return value

The index of the first occurrence of the specified substring, or -1 if not found.

Examples

"banana".indexOf("na")
2
"banana".indexOf("no")
-1