title: JavaScript Loop and wait for function
body: <p>I have a simple single-dimension array, let's say:</p>
  
  <pre><code>fruits = ["apples","bananas","oranges","peaches","plums"];
  </code></pre>
  
  <p>I can loop through with with <code>$.each()</code> function:</p>
  
  <pre><code>$.each(fruits, function(index, fruit) {  
     showFruit(fruit);
  });
  </code></pre>
  
  <p>but I'm calling another function which I need to finish before moving on to the next item.</p>
  
  <p>So, if I have a function like this:</p>
  
  <pre><code>function showFruit(fruit){
      $.getScript('some/script.js',function(){
          // Do stuff
      })
  }
  </code></pre>
  
  <p>What's the best way to make sure the previous fruit has been appended before moving on?</p>