Find the index of a substring inside a string
suggest changeindexOf 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
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents