title: Generate select options from array and select multiple element by comparing with another array (jQuery)
body: <p>What I want to do is to generate <code>option</code> elements for a multiple <code>select</code> drop-down from a JavaScript array. Than select each option in the drop-down that is the same as the value in another array (The <code>results</code> array in the example).</p>
  
  <p>The problem is that when the results array has multiple elements, the original options get multiplied in the HTML for the number of elements in the results array.</p>
  
  <p>I understand why this is happening, but I cant seem to find a better solution then the one I currently use, which is something like this:</p>
  
  <pre><code>var
  options = ['Some value', 'Another value', 'Third value', 'Something completely different'],
  results = ['Some value', 'Another value'],
  selectHtml;
  
  $.each( options, function( index, value ) {
      var option = value;
  
      $.each( results, function( index, value ) {
          if ( option === value ) {
              selectHtml += '&lt;option selected="selected" value="' + option + '"&gt;' + option + '&lt;/option&gt;';
          }
          else {
              selectHtml += '&lt;option value="' + option + '"&gt;' + option + '&lt;/option&gt;';
          }
      });
  });
  </code></pre>
  
  <p>You can find a live example here: <a href="http://jsfiddle.net/wCWyp/" rel="nofollow">http://jsfiddle.net/wCWyp/</a></p>
  
  <p>What I want to accomplish is the same thing, but without the multiplication of the elements.</p>