indexOf
优质
小牛编辑
136浏览
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); }
Name | Type(s) | Description |
---|---|---|
substring | string | The substring to search for. |
startIndex | number? | The index from which to start the search. |
returns | number | 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