Find the index of a substring inside a string

suggest change

indexOf returns the index of the first match, or -1 when there is no match. 'Wor' begins at index 6 in 'Hello World' (the characters are 0 through 10).

'Hello World'.indexOf('Wor');    // 6

The second argument is the index at which to start the search.

"harr dee harr dee harr".indexOf("dee", 10); // 14

The search is case-sensitive.

'Hello World'.indexOf('WOR');    // -1

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents