jQuery inArray() methodThe jQuery inArray() method is used to find a specific value in the given array. If the value found, the method returns the index value, i.e., the position of the item. Otherwise, if the value is not present or not found, the inArray() method returns -1. This method does not affect the original array. If the item occurs more than once, the inArray() method returns the index value of the first occurrence. The index of the array begins with 0, so if the value is matched with the first item, the inArray() method returns 0. SyntaxThe inArray() method accepts some parameter values that are defined as follows - val: It is the item to search for. arr: It is an array through which to search. index: It is the array index at which to start the search. Example1In this example, we are using the inArray() method to search the specified element from the array. Here, there is an array arr including some elements, and we are finding the item "A" from the array arr. Although the item "A" is occurring many times in the array arr, but the method will return the index of the first occurrence. Test it NowOutput After the execution of the above code, the output will be - After clicking the given button, the output will be - Example2This example is similar to the previous example, except that here we are using the index parameter of the inArray() method along with other arguments. The method will search the element "A" at index value 4 in the given array arr and will return -1. It is because the string "AA" is present at index value 4 of the array arr. Test it NowOutput After the execution of the above code, the output will be - After clicking the given button, the output will be - Next TopicjQuery dblclick() method |