title: In jQuery is it more efficient to use filter(), or just do so in the each()?
body: <p>I currently have code that is pulling in data via jQuery and then displaying it using the <code>each</code> method.</p>
  
  <p>However, I was running into an issue with sorting, so I looked into using, and added, jQuery's <code>filter</code> method before the <code>sort</code> (which makes sense).</p>
  
  <p>I'm now looking at removing the <code>sort</code>, and am wondering if I should leave the <code>filter</code> call as-is, or move it back into the <code>each</code>.</p>
  
  <p>The examples in the <a href="http://api.jquery.com/filter/" rel="noreferrer">jQuery API documentation for filter</a> stick with styling results, not with the output of textual content (specifically, not using <code>each()</code>).</p>
  
  <p>The documentation currently states that "[t]he supplied selector is tested against each element [...]," which makes me believe that doing a <code>filter</code> <em>and</em> an <code>each</code> would result in non-filtered elements being looped through twice, versus only once if the check was made solely in the <code>each</code> loop.</p>
  
  <p>Am I correct in believing that is more efficient?</p>
  
  <p>EDIT: Dummy example.</p>
  
  <p>So this:</p>
  
  <pre><code>// data is XML content
  data = data.filter(function (a) {
      return ($(this).attr('display') == "true");
  });
  data.each(function () {
      // do stuff here to output to the page
  });
  </code></pre>
  
  <p>Versus this:</p>
  
  <pre><code>// data is XML content
  data.each(function () {
      if ($(this).attr('display') == "true") {
          // do stuff here to output to the page
      }
  });
  </code></pre>