Show Menu
TOPICS×

indexOf

Checks if the first argument string ends with a specific string (second argument string). If the string is not found, return -1.

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.