title: Jquery $.each loop counter
body: <p>i am running this code when data is typed in a text input:</p>
  
  <pre><code>$("input#search").live("keyup", function(e) {       
          var search_string = $(this).val();
          var i = 0;
          var trHTML = '';
          if(search_string !== '') {
              $.ajax({
                  type: "POST",
                  dataType: "json",
                  url: "/section/search_go",
                  data: { query: search_string },
                  cache: false,
                  success: function(response) {
                      $.each(response, function(i, item) {
  
  
                          trHTML += '&lt;tr&gt;';
                          trHTML += '&lt;td&gt;' + item.accountnumber + '&lt;/td&gt;';
                          trHTML += '&lt;td&gt;' + item.company + '&lt;/td&gt;';
                          trHTML += '&lt;td&gt;' + item.phone + '&lt;/td&gt;';
                          trHTML += '&lt;td&gt;' + item.postcode + '&lt;/td&gt;';
                          trHTML += '&lt;/tr&gt;';
                      });
                      $('#customers').html(trHTML);
                  }
              });
              console.log(i);
          }
  
          /*if(counter === 0 || search_string == '') {
              $('#customers').html('&lt;tr&gt;&lt;td colspan="4"&gt;No Results&lt;/td&gt;&lt;/tr&gt;');
          }*/
      });
  </code></pre>
  
  <p>i am trying to get the number of records in the <code>$.each</code> loop but i cannot seem to do that.</p>
  
  <p>i have tried using <code>i</code> which is in the function and i also tried adding a <code>counter</code> variable and for each loop i added <code>counter++</code> but that still isnt working</p>