It returns an index of the first occurrence of a given search element.
- searchElement: indicates element to be searched
- number : indicates an index of the first occurrence of the element to be searched
var studNames = ["Ram", "Ravi", "Raju", "Raghu", "Gopal"]; document.write(studNames.indexOf("Ravi")); //1
- In this first line above code, we have created an array variable “studNames” and assigned five string values.
- Then we find the index value of a particular string in “studNames”, we need to use the indexOf() operation. The index of the value to be found must be given in the function