jQuery Data Type How to - Check if element index in an array








Question

We would like to know how to check if element index in an array.

Answer


<html>
  <head>
    <script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type="text/javascript">
        $(document).ready(function(){<!--from ww  w. j  av  a 2  s .  co m-->
              var arr = [ 4, "A", 8, "B" ];
              console.log(jQuery.inArray("A", arr));
        });
    </script>
  </head>
  <body>
</html>

The code above is rendered as follows: