How do we Use JavaScript IndexOf Operation in Array

Indexof JavaScript Array

In this article, we will learn about indexof the javascript array.

IndexOf() Method:

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
  1. In this first line above code, we have created an array variable “studNames” and assigned five string values.
  2. 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
READ ALSO  Example to Understand How to Create a Class in JavaScript

Leave a Reply