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

indexOf

优质
小牛编辑
132浏览
2023-12-01

Finds the index of the first occurrence of the given substring within this sequence, starting from the specified index (or the beginning of the sequence).

Signature

StringLikeSequence.indexOf = function(substring, startIndex) { /*...*/ }
StringLikeSequence.indexOf = function indexOf(substring, startIndex) {
  return this.toString().indexOf(substring, startIndex);
}
NameType(s)Description
substringstring

The substring to search for.

startIndexnumber?

The index from which to start the search.

returnsnumber

The first index where the given substring is found, or -1 if it isn't in the sequence.

Examples

Lazy('canal').indexOf('a')    // => 1
Lazy('canal').indexOf('a', 2) // => 3
Lazy('canal').indexOf('ana')  // => 1
Lazy('canal').indexOf('andy') // => -1
Lazy('canal').indexOf('x')    // => -1