lastIndexOf()
Table of Contents
Overview
The lastIndexOf() function takes string and searchString as arguments. It returns the last 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>.lastIndexOf(<searchString>);
(OR)
<variable> = lastIndexOf( <string>, <searchString> );
Parameter | Description | Data type |
---|---|---|
<variable> | Variable which will contain the returned index number. | NUMBER |
<string> | The string from which the index number will be returned. | TEXT |
<searchString> |
| TEXT |
Examples
text="Hello world, welcome to the universe";
lastIndex = text.lastIndexOf("e"); //returns 35
lastIndex = text.lastIndexOf("e"); //returns 35