title: How to populate a <select> element with dynamic values in JQuery?
body: <p>I have 5 select elements with same class. </p>
  
  <pre><code>    &lt;select class="form-control rating"&gt;&lt;/select&gt;
      &lt;select class="form-control rating"&gt;&lt;/select&gt;
      &lt;select class="form-control rating"&gt;&lt;/select&gt;
      &lt;select class="form-control rating"&gt;&lt;/select&gt;
      &lt;select class="form-control rating"&gt;&lt;/select&gt;
  </code></pre>
  
  <p>I want to populate them with dynamic rating values with jQuery.
  Like: <code>rateArr=[5,2,2,3,5]</code></p>
  
  <p>What I actually want, like this: </p>
  
  <pre><code>    &lt;select class="form-control rating"&gt;
           &lt;option value="1"&gt;1&lt;/option&gt;
           &lt;option value="2"&gt;2&lt;/option&gt;
           &lt;option value="3"&gt;3&lt;/option&gt;
           &lt;option value="4"&gt;4&lt;/option&gt;
           &lt;option value="5"&gt;5&lt;/option&gt;
      &lt;/select&gt;
      &lt;select class="form-control rating"&gt;
           &lt;option value="1"&gt;1&lt;/option&gt;
           &lt;option value="2"&gt;2&lt;/option&gt;
      &lt;/select&gt;
      &lt;select class="form-control rating"&gt;
           &lt;option value="1"&gt;1&lt;/option&gt;
           &lt;option value="2"&gt;2&lt;/option&gt;
      &lt;/select&gt;
      &lt;select class="form-control rating"&gt;
           &lt;option value="1"&gt;1&lt;/option&gt;
           &lt;option value="2"&gt;2&lt;/option&gt;
           &lt;option value="3"&gt;3&lt;/option&gt;
      &lt;/select&gt;
      &lt;select class="form-control rating"&gt;
           &lt;option value="1"&gt;1&lt;/option&gt;
           &lt;option value="2"&gt;2&lt;/option&gt;
           &lt;option value="3"&gt;3&lt;/option&gt;
           &lt;option value="4"&gt;4&lt;/option&gt;
           &lt;option value="5"&gt;5&lt;/option&gt;
      &lt;/select&gt;
  </code></pre>
  
  <p>But couldn't sort it out how to approach to solve. So far what i was trying:</p>
  
  <pre><code>$('.rating').each(function(index,row){ 
      for(i=1; i&lt;= rateArr[index]; i++){
           $(this).append($("&lt;option&lt;/option&gt;").text(i).val(i));
      }
  });
  </code></pre>