12 April 2016

JavaScript runs asynchronously, that means when you initialize $.each every bit of code that comes after that will not be executed when $.each has finished. Sometimes you need your code to be executed after each. I found out that the easiest way to do it is to use $.when and $.then.

Source code viewer
  1. (function($){$().ready(function() {
  2.  
  3. $.when(
  4. $.each(my_array, function(i, obj) {
  5. console.log(obj);
  6. })
  7. ).then(function(){
  8. alert('My after each event.');
  9. });
  10.  
  11. });})(jQuery);
Programming Language: jQuery