title: Populating a jquery array from values of a select using each
body: <p>I'm trying to populate an array in Jquery with selected values from a select.</p>
  
  <p>Here is my jquery (no ajax call because I first want to make the array before i call ajax to input fields into db)</p>
  
  <pre><code>$('#add-group-form').submit(function(e) {
      e.preventDefault();
      var contactsArr = [];
      $("select option").each(function(i, val){
          var $val = $(val);
          if($(i).attr('selected', 'selected')){
          contactsArr.push({value: $val.val()});
          }
      });
      console.log(contactsArr);
  });
  </code></pre>
  
  <p>Now in all honesty i got the each from a different source.</p>
  
  <p>Not sure how i check the attribute to make sure it is selected.</p>
  
  <p>Thanks in advance for the help</p>
  
  <p>**EDIT: </p>
  
  <p>Okay so I may have forgotten to check for answers as I got distracted by trying to figure it out</p>
  
  <p>This is how I've done it (tested and works in my system).</p>
  
  <pre><code>var contactsArr = [];
  $(".edit-contact-select option:selected").each(function() {
      contactsArr.push({value: $(this).val()});
  });
  </code></pre>
  
  <p>I was over-complicating the entire thing. </p>