How to find index of element in array using jQuery

Today, for my project requirement, I need to find out index of any element in jQuery. I found the solution. jQuery provides a method called "inArray" which search for the specified value in the array and returns the index of the element.

Earlier I had posted about jQuery solution to remove item from array, split an array, combine/join arrays and remove duplicate items from array, And In this post, see how to find index of element in array with example.

Prototype of method
inArray("Value to search for", "Array in which value needs to be searched");

Below jQuery code snippets provides you an overview of how to use inArray() method.

  var arrData = [ "j", "Q", "u", "e","r","y" ];
  alert(jQuery.inArray("Q", arrData));

When run, it will alert 1 as index starts from 0. Cool and simple.

See live Demo and Code.

Feel free to contact me for any help related to jQuery. I will gladly help you.