title: How to check if jQuery object exist in array?
body: <p>Given an <code>item</code> and an <code>array</code>, I would like to know if <code>item</code> exist in <code>array</code>.</p>
  
  <p><code>item</code> is a jQuery object, e.g. <code>$(".c")</code>. You can assume that <code>item.length == 1</code>.</p>
  
  <p><code>array</code> is an array of jQuery objects, e.g. <code>[$(".a"), $(".b")]</code>. Each item in this array may represent 0, 1, or more objects.</p>
  
  <p>Here is how I thought to implement this: (<a href="http://jsfiddle.net/e3WwB/1/" rel="noreferrer">live demo here</a>)</p>
  
  <pre><code>function inArray(item, arr) {
      for (var i = 0; i &lt; arr.length; i++) {
          var items = $.makeArray(arr[i]);
  
          for (var k = 0; k &lt; items.length; k++) {
              if (items[k] == item[0]) {
                  return true;
              }
          }
      }
  
      return false;
  }
  </code></pre>
  
  <p>Can you find a more elegant implementation?</p>
  
  <hr>
  
  <p><strong>Example:</strong></p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;div class="a"&gt;Hello&lt;/div&gt;
  &lt;div class="a"&gt;Stack&lt;/div&gt;
  &lt;div class="a"&gt;Overflow&lt;/div&gt;
  
  &lt;div class="b"&gt;Have&lt;/div&gt;
  &lt;div class="b"&gt;a&lt;/div&gt;
  &lt;div class="b"&gt;nice&lt;/div&gt;
  &lt;div class="b"&gt;day!&lt;/div&gt;
  
  &lt;div class="c"&gt;Bye bye&lt;/div&gt;
  </code></pre>
  
  <p>JS:</p>
  
  <pre><code>console.log(inArray($(".a").eq(2), [$(".a"), $(".b")])); // true
  console.log(inArray($(".b").eq(3), [$(".a"), $(".b")])); // true
  console.log(inArray($(".c"), [$(".a"), $(".b")]));       // false
  console.log(inArray($(".a").eq(2), [$(".b")]));          // false
  console.log(inArray($(".a").eq(2), []));                 // false
  console.log(inArray($(".c"), [$("div")]));               // true
  </code></pre>