The JavaScript string object contains an indexOf method. It returns the index in the string of the first occurrence of a specified character. The index is numbered starting at 0. For example:
var strTest = 'only one day';
document.write(strTest.indexOf('n'));
The index returned in the preceding example is 1, as 'n' is the second character in the string and string indexes are counted starting at 0.
The indexOf method accepts an optional second argument – the position at which to begin the search.
var strTest = 'only one day';
document.write(strTest.indexOf('n',2));
In this example the index returned is 6. Since the search started at the second character position, the 'n' that exists at character position 1 is skipped and the next 'n' is searched for, which exists at position 6.