The index of the first occurrence of searchString
found, or -1
if not found.
Return value when using an empty search string
Searching for an empty search string produces strange results. With no second argument, or with a second argument whose value is less than the calling string's length, the return value is the same as the value of the second argument:
"hello world".indexOf("");
"hello world".indexOf("", 0);
"hello world".indexOf("", 3);
"hello world".indexOf("", 8);
However, with a second argument whose value is greater than or equal to the string's length, the return value is the string's length:
"hello world".indexOf("", 11);
"hello world".indexOf("", 13);
"hello world".indexOf("", 22);
In the former instance, the method behaves as if it found an empty string just after the position specified in the second argument. In the latter instance, the method behaves as if it found an empty string at the end of the calling string.