JavaScript Array indexOf()

The JavaScript array indexOf() method is used to search the specified element in the given array and returns the index of the first match.

Syntax:

array.indexOf (element,index)

Parameters:
element: It is required and represents the element that has to be searched.
index: It is optional and represents the index position from where the search starts.

Returns:
Index of the first match for a specific element.

Example:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
var a = ["GOLD","SILVER","DIAMOND","RUBY","PLATINUM"]
var result=a.indexOf("DIAMOND");
document.writeln(result);
</script>
</body>
</html>