title: How to reference multiple index values of an array without a for-loop?
body: <p>How do I specify multiple index values of an array without iterating through all of them?</p>
  
  <p>I have an array: <code>var boxArray = $(’.box’).toArray();</code>. I have 9 elements with the class <code>box</code>, so this array is comprised of the index values <code>[0, 1, 2, 3, 4, 5, 6, 7, 8]</code>.</p>
  
  <p>If <code>boxArray</code> index values of <code>[0]</code>, <code>[4]</code>, and <code>[8]</code> are all given a class of <code>clicked</code>, I want something to happen. I know I can use a <code>for</code> loop to iterate through the entire array, and I know I can reference just one index value (<code>boxArray[0]</code>), but how would I denote multiple out-of-order index values at once?</p>
  
  <p><code>$(boxArray[0, 4, 8])</code> doesn’t work - only the last index value is recognized. <code>$(boxArray[0][4][8])</code> doesn’t work</p>
  
  <p>Is the only way to do this in JavaScript and jQuery to reference them one at a time? Ideally I'd like to be able to do something like this:</p>
  
  <pre><code>if ($(boxArray[0, 4, 8]).hasClass(‘clicked’)) {
    // do something;
  }
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>if ($(boxArray[0]).hasClass('clicked') &amp;&amp;
      $(boxArray[4]).hasClass('clicked') &amp;&amp;
      $(boxArray[8]).hasClass('clicked')
  ) {
    // do something
  }
  </code></pre>