JavaScript String indexOf() Method
The indexOf javascript () method returns the position of the first occurrence of an element of a string or arrays. This method returns -1 if the value is not found or NULL. It is a case-sensitive method.
SYNTAX – string.indexOf(searchValue, start)
Where,
The string represents the given string to be checked on.
searchValue – required value to search for
start – The position from where to start. It is an optional field. If start<0, the search starts from the back of the string i.e. start+string length is used.
The method returns the first position where the value exists. It returns -1 if the value never occurs. The method compares the search Value with elements of the array or string using strict equality. In arrays, if the slots are empty, it skips them.
indexOf() is an ESI feature and it is supported by all browsers.
For Example –