JavaScript Array indexOf() method
returns the first index at which a given element can be found in the array

indexOf() method returns the first index at which a given element can be found in the array.

syntax

indexOf(element, start)

element element to locate in the array.

start (optional). Where to start the search in the array.

Negative start index counts back from the end of the array.

indexOf() method returns the first index at which a given element can be found in the array.

indexOf() method returns -1 if the value is not found.

indexOf() method does not change the original array.

indexOf() method is case-sensitive.

syntax 1 description
return index of first occurrence of element in myArray
myArray.indexOf(element)
syntax 2 description
return index of first occurrence of element in myArray from start position
myArray.indexOf(element, start)