Choose where you’d like to start

indexOf()

Overview

The indexOf() function takes string and searchString as arguments. It returns the first occurrence index of searchString's first character in the string.

If the searchString is not found in the string, it returns -1.

Note:

  • Index starts from 0.
  • This function performs a case-sensitive search.

Return Type

  • Number

Syntax

<variable> = <string>.indexOf( <searchString> );

(OR)

<variable> = indexOf( <string>, <searchString>);

(OR)

<variable> = <string>.find(<searchString>);

(OR)

<variable> = find(<string>,<searchString>);
ParameterDescriptionData type
<variable>Variable which will contain the returned index number.NUMBER
<string>The string from which the index number will be returned.TEXT
<searchString>This string's first character's first occurrence will be checked in the string.TEXT

Examples

text="Hello world, welcome to the universe";
firstIndex = text.indexOf("e");             //returns 1

Get Started Now

Execute