lastIndexOf function

The lastIndexOf function returns the position of the last found occurrence of a specified value in a string.
Arguments
1–2, Optional arguments are indicated by a ? following the argument name.
argument Description
search string A string representing the value to search for.
position?

Specifies the position at which to start the search (searching backwards).

If this argument is not present, 0 is assumed, and the entire string is searched.

Return values (number)
A number indicating the position of the last occurrence of search string.
  • A new string containing the extracted substring of the given string.
  • -1, if the value to search for never occurs.
  • The index of the greatest such position (at one or more positions that are smaller than or equal to position), if converting this object to a string results in search string appearing as a substring.
Syntax
str.lastIndexOf(search string)
Examples
Example Result
Assuming that you have a module parameter, CONTROL1/VALUE1AND2.CV, with a value of “T1=47 T2=67”.
var str1 = DLSYS["CONTROL1/VALUE1AND2.CV"];
this.Label = str1.lastIndexOf("T");
Returns "6".
'canal'.lastIndexOf('a')
Returns "3".