The indexOf() method is used to returns the first index at which a given element can be found in the array, or -1 if it is not found. The array is searched forwards (front to back).
This method has the form:
|searchElement||(required) Specifies the element to be located in the array|
|fromIndex||(optional) Specifies the index at which to begin the search (default = 0)
If the fromIndex is greater than the length of the array, -1 is returned
If the fromIndex is less than zero, the search begins at the offset from the end of the array
Note: In all cases, the array is searched from front to back
A Number that indicates the position of searchElement, or -1 if not found
The following example shows the basic use of this method.
<script> var cols = [ "Cyan", "Magenta", "Yellow", "Black" ]; document.write(cols.indexOf("Magenta")); </script>
This produces the following result:
This form was added in version: 1.6