Can't get items to push to an array
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/2768293/waiting-on-multiple-asynchronous-calls-to-complete-before-continuing">Waiting on multiple asynchronous calls to complete before continuing</a>  </p>
</blockquote>



<p>Update: </p>

<p>Here is the HTML form that lets the user select one or more timelines:</p>

<pre><code>&lt;form&gt;
  &lt;ul&gt;
    &lt;li&gt;
      &lt;input type="checkbox" id="s-fry" data="stephenfry" /&gt;
      &lt;label for="s-fry"&gt;Stephen Fry&lt;/label&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;input type="checkbox" id="r-dawkins" data="richarddawkins" /&gt;
      &lt;label for="r-dawkins"&gt;Richard Dawkins&lt;/label&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;input type="checkbox" id="s-macfarlane" data="sethmacfarlane" /&gt;
      &lt;label for="s-macfarlane"&gt;Seth MacFarlane&lt;/label&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;input type="checkbox" id="r-gervais" data="rickygervais" /&gt;
      &lt;label for="r-gervais"&gt;Ricky Gervais&lt;/label&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
  &lt;input type="submit" value="Go" /&gt;
&lt;/form&gt;
&lt;div id="tweets"&gt;&lt;/div&gt;
</code></pre>

<p>And here's the JavaScript</p>

<pre><code>$('input[type=submit]').on('click', function(e){

// prevent default behavior of the submit button
e.preventDefault();

// empty the div with ID of tweets
$('#tweets').empty();

// create an empty ul
var tweetList = $('&lt;ul id="tweets-list"&gt;');

// create an empty array for the tweets
var returnedTweets = [];

// perform a function on all of the checked boxes
$(':checkbox:checked').each( function(){

var twitterID = $(this).attr('data');

// use the "data" attribute to build the query string for getJSON
$.getJSON( 'http://api.twitter.com/1/statuses/user_timeline/'+twitterID+'.json?callback=?', null, function(data){
    $.each(data, function(i, tweet){ 
      returnedTweets.push(tweet); 
    });
    returnedTweets.sort(function(a,b){ return b.id - a.id; });
    $.each(returnedTweets, function(i, tweet){
      var item  = $('&lt;li&gt;');
      var name  = $('&lt;h2&gt;').text(tweet.user.name);
      var date  = $('&lt;small&gt;').text(prettyDate(tweet.created_at));
      var img   = $('&lt;img&gt;').attr('src', tweet.user.profile_image_url);
      var msg   = $('&lt;p&gt;').text(tweet.text);
      item.append(img,name,date,msg);
      tweetList.append(item);
    }); // end of parse
}); // end of getJSON
}); // checkbox.each

$('#tweets').append(tweetList);

function prettyDate(time){
var date = new Date((time || "").replace(/-/g,"/").replace(/[TZ]/g," ")),
diff = (((new Date()).getTime() - date.getTime()) / 1000),
day_diff = Math.floor(diff / 86400);

if ( isNaN(day_diff) || day_diff &lt; 0 || day_diff &gt;= 31 )
return;

return day_diff == 0 &amp;&amp; (
      diff &lt; 60 &amp;&amp; "just now" ||
      diff &lt; 120 &amp;&amp; "1 minute ago" ||
      diff &lt; 3600 &amp;&amp; Math.floor( diff / 60 ) + " minutes ago" ||
      diff &lt; 7200 &amp;&amp; "1 hour ago" ||
      diff &lt; 86400 &amp;&amp; Math.floor( diff / 3600 ) + " hours ago") ||
  day_diff == 1 &amp;&amp; "Yesterday" ||
  day_diff &lt; 7 &amp;&amp; day_diff + " days ago" ||
  day_diff &lt; 31 &amp;&amp; Math.ceil( day_diff / 7 ) + " weeks ago";
} // end of prettyDate

}); // end of "click" function
</code></pre>

<p>It is sorting the array before output, but it's not sorting chronologically, as intended. Here is an updated fiddle: <a href="http://jsfiddle.net/brianeoneill/FsYKg/" rel="nofollow">http://jsfiddle.net/brianeoneill/FsYKg/</a> </p>
