title: How to ensure jQuery $.each is finished before continuing
body: <p>I am working on a jQuery plugin with an <code>add_record</code> method (see below). If you look at the function definition, there are two <code>$.each</code> loops that append values to plugin.payload.</p>
  
  <p>Right now, everything works fine. However, what if records or options is really big? Do I need to be concerned about the <code>$.each()</code> not finishing before the transmit call is issued?</p>
  
  <p>If so, what is the best way to address the issue?</p>
  
  <pre><code>plugin.add_record = function (records, options, callback) {
      if (typeof (options) == "function") {
          callback = options;
          options = undefined;
      }
      if (options) {
          $.each(options, function (index, value) {
              plugin.payload.append($(value));
          });
      }
      $.each(records, function (index, value) {
          plugin.payload.append($(value));
      });
      transmit('API_AddRecord', plugin.payload, 'db', function (data) {
          return typeof (callback) == "function" ? callback(data) : data;
      });
  }
  </code></pre>