1
2var str = "Please locate where 'locate' occurs!";
3
4var ind1 = str.indexOf("locate"); // return location of first value which founded
5var ind2 = str.lastIndexOf("locate"); // return location of last value which founded
6var ind3 = str.indexOf("locate", 15); // start search from location 15 and then take first value which founded
7var ind4 = str.search("locate");
8//The search() method cannot take a second start position argument.
9//The indexOf() method cannot take powerful search values (regular expressions).
10
11document.write("<br>" + "Length of string:", len);
12document.write("<br>" + "indexOf:", ind1);
13document.write("<br>" + "index of last:", ind2);
14document.write("<br>" + "indexOf with start point:", ind3);
15document.write("<br>" + "search:", ind4);