The JavaScript indexOf() String Method

By: Dusty Arlia
Published on Tuesday, April 2, 2013, 02:25 PM
Last Updated on Thursday, July 16, 2015 at 8:24 PM
Total Updates: 3

The JavaScript indexOf() string method will search inside a string for a given value. If that value is found, it will return the position of its first occurrence. If that value isn't found, the indexOf() method will return the value -1.

For example:

var greeting = "Happy Birthday to Tom!";
var string_location = greeting.indexOf("Tom");
document.write(string_location);

This should print 18 to the screen.

Comments:

Ad: