JavaScript Strings Find the index of a substring inside a string

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9

Example

The .indexOf method returns the index of a substring inside another string (if exists, or -1 if otherwise)

'Hellow World'.indexOf('Wor');    // 7

.indexOf also accepts an additional numeric argument that indicates on what index should the function start looking

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

You should note that .indexOf is case sensitive

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


Got any JavaScript Question?