string.lastIndexOf()
Get the index of the last matching substring within a String.
Signature
lastIndexOf(pattern: String) => Number | Null
lastIndexOf(pattern: String, end: Number) => Number | Null
Examples
-
Get the location of the last occurrence of the String "200" at or below index location 27:
"HTTP/1.1 200 OK - SUCCESS (200)".lastIndexOf("200", 27)
27
-
Get the location of the last occurrence of the String "200" at or below index location 20:
"HTTP/1.1 200 OK - SUCCESS (200)".lastIndexOf("200", 20)
9
-
Get the location of the last occurrence of the String "200" at or below index location 8, which fails because the String isn’t found:
"HTTP/1.1 200 OK - SUCCESS (200)".lastIndexOf("200", 8)
null