Parameters: This method accepts two parameters as mentioned above and described below:
- element: This parameter holds the element whose index will be returned.
- start: This parameter is optional and it holds the starting point of the array, where to begin the search the default value is 0.
Return value: This method returns the index of the first occurrence of the element. If the element cannot be found in the array, then this method returns -1.
Below is an example of the Array indexOf() method.
Example 2: In this example, the method will be searched for element 2 in that array and return that element index.
Example 3: In this example, the method will be searched for element 9 in that array if not found then return -1.
- Google Chrome 1 and above
- Edge 12 and above
- Firefox 1.5 and above
- Internet Explorer 9 and above
- Opera 9.5 and above
- Safari 3 and above
Please Login to comment...