foreach loop wait until each function in each step is completed

In my code:

jQuery.each(data.modules, function(key, value) {    
       doSomethingLong(value);
})  // end each

function doSomethingLong(value) {
    //some ajax calls
};

In this case all the functions doSomethingLong() running at once.

I need to wait until doSomethingLong(value) in each step returns true / false.

How can i get it in javascript or jQuery?

Answers 1

  • simply try this

    data.modules.forEach(function(value){
      doSomethingLong(value);
    });
    

    basically data.modules is an array which you can iterate using forEach method.


Related Articles