String.lastIndexOf
lastIndexOf($substring, $options = {}) -> number
Description
Find the position of a substring, starting at the end of the string.
If the substring does not exist, it will return 0
.
'one fish two fish'.lastIndexOf('one') //= 1 'one fish two fish'.lastIndexOf('fish') //= 14 ^ 'one fish two fish'.lastIndexOf('bird') //= 0
Options
Option | Value | Description |
---|---|---|
ignoreCase |
true/false | Match upper and lowercase versions of each character. |
startAt |
number | Start at index position (default: 1) |
'one fish two fish'.lastIndexOf('Two Fish', -ignoreCase) //= 10 ^ 'one fish two fish'.lastIndexOf('Fish', { ignoreCase, startAt: 10 }) //= 14 ^