JavaScript Array indexOf() Method

The JavaScript array indexOf() method is used to search the position of a particular element in a given array. This method is case-sensitive.

The index position of first element in an array is always start with zero. If an element is not present in an array, it returns -1.


array.indexOf(item, start)

Paramaters: This method accepts two parameters as mentioned above and described below:

  • element: This parameter holds the element which index will be return.
  • start: This parameter is optional and it holds the starting point of the array, where to begin the search the default value is 0.


var fruits = ["Banana", "Orange", "Apple", "Mango", "Banana", "Orange", "Apple"];
var a = fruits.indexOf("Apple", 4);

Example -