lastIndexOf
优质
小牛编辑
137浏览
2023-12-01
Finds the index of the last occurrence of the given substring within this sequence, starting from the specified index (or the end of the sequence) and working backwards.
Signature
StringLikeSequence.lastIndexOf = function(substring, startIndex) { /*...*/ }
StringLikeSequence.lastIndexOf = function lastIndexOf(substring, startIndex) { return this.toString().lastIndexOf(substring, startIndex); }
Name | Type(s) | Description |
---|---|---|
substring | string | The substring to search for. |
startIndex | number? | The index from which to start the search. |
returns | number | The last index where the given substring is found, or -1 if it isn't in the sequence. |
Examples
Lazy('canal').lastIndexOf('a') // => 3 Lazy('canal').lastIndexOf('a', 2) // => 1 Lazy('canal').lastIndexOf('ana') // => 1 Lazy('canal').lastIndexOf('andy') // => -1 Lazy('canal').lastIndexOf('x') // => -1