String.lastIndexOf(text) Last updated: 30. May 2026

Searches for the last occurrence of a substring within a string.

Parameters

Name Type Description
text string

Sub text to search for within text.

Returns

The last index of the occurrence.

Example

Code example (#JS)

#JS is mixed HTML (or other text file) with inline JavaScript with # starting and ending each inline statement.
#{
    var text = "Test test";
    var search = "test";
    var notfound = "xyz";
}#

<b>Found in string:</b>
#{
    var index = text.lastIndexOf(search);
    write(index);
}#


<b>Not found in string:</b>
#{
    index = text.lastIndexOf(notfound);
    write(index);    
}#

Output

The #JS code above produces the output shown below:

<b>Found in string:</b>
5

<b>Not found in string:</b>
-1