当前位置: 首页 > 文档资料 > Lazy.js 英文文档 >

lastIndexOf

优质
小牛编辑
132浏览
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);
}
NameType(s)Description
substringstring

The substring to search for.

startIndexnumber?

The index from which to start the search.

returnsnumber

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