title: How to make Jquery $.each loop wait for operation to complete before iterating?
body: <p>I have a function that has a $.each to loop over keys of an object and do stuff. within this loop i am calling a function which in turns makes a call to the server to get some data and does things with it in a callback. these calls are asynchronous so the $.each does not wait for the data to come and the callback to do what its supposed to and keeps iterating. How do i make the $.each loop wait till i complete my operation and then continue. </p>
  
  <pre><code>$.each(messages,function(key) {  
  //do something 
  if(some Condition) {
  getfromserver(token,myCallback); }
  //do something 
  });
  
  
  
  
  function myCallback(data)
   {
     //do something with data
   }
  </code></pre>