indexOf

Last update: 2023-06-20
  • Created for:
  • Experienced
    Developer

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.

On this page