JavaScript IndexOf string function returns the starting index of the specified string pattern from the provided string. JavaScript IndexOf function starts traversing the string from left side of the provided string and returns the first occurrence of the specified string pattern. Try the sample below: