title: How to get index value from jquery .each() function
body: <p>I'm having trouble fetching the index of another field from 
  jquery .each() function. I want to fetch the value of the 
  input with the name line_id[] :</p>
  
  <pre><code>$('input[name=bl_caps[]]').each(function(index){
  
      var line_id = $('input[name=line_id[]]').val();
      var caps = $(this).val();
      alert('line id: ' + line_id + '&lt;br/&gt;' + 'caps: ' + caps);
  
  });
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;?php foreach(){ ?&gt;
  &lt;input type="hidden" name="line_id[]" id="line_id" value="&lt;?php echo $sbl-&gt;BusLineID; ?&gt;"/&gt;
  &lt;td&gt;&lt;input type="text" name="bl_caps[]" id="bl_caps"/&gt;&lt;/td&gt;
  &lt;?php } ?&gt;
  </code></pre>
  
  <p>I'm planning to do it like this:</p>
  
  <pre><code>var line_id = new Array();
  
                          $('input[name=line_id[]]').each(function(index){
                              line_id[index] = $(this).val();
                          });
  
  
                          $('input[name=bl_caps[]]').each(function(index){
  
                              var line_ids = line_id[index];
                              var caps = $(this).val();
                              alert('line id: ' + line_ids + '&lt;br/&gt;' + 'caps: ' + caps);
  
                          });
  </code></pre>
  
  <p>But I'm hoping that I could find a better answer here:)</p>