String.indexOf
indexOf($substring, $options = {}) -> number
Description
Find the index position of a substring.
If the substring does not exist, it will return 0
.
Note: To simply check if the substring exists, see contains().
'abc xyz'.indexOf('abc') //= 1 'abc xyz'.indexOf('xyz') //= 5 'abc xyz'.indexOf('jkl') //= 0
Options
Option | Value | Description |
---|---|---|
ignoreCase |
true/false | Match upper and lowercase versions of each character. |
startAt |
number | Start at index position (default: 1) |
'abc xyz'.indexOf('XYZ', -ignoreCase) //= 5 'abc xyz'.indexOf('XYZ', { ignoreCase, startAt: 3 }) //= 5