indexOf indexOf

Returns the position (in the first argument) of the first occurrence of the second parameter. Returns -1 if there is no match.

Category

String

Function syntax

indexOf(<parameters>)

Parameters

Parameter
Type
string
String
specified value
String

Signature and returned type

indexOf(<string>,<string>)

Returns an integer.

Example

indexOf("Hello", "l")

Returns 2.

Explanation:

In “Hello”, the first occurrence of “l” is at position 2.

recommendation-more-help
b22c9c5d-9208-48f4-b874-1cefb8df4d76