Below are my multiple ajax calls in each loop.
var getApiVendorslist = $.getJSON("url");
var sum = 0;
 getApiVendorslist.then(function(res) {
    console.log("Completed Fetching List of vendors");
    $.each(res.data, function(k, v) {
        var ajaxCall = $.getJSON(url);
        ajaxCall.then(function(result) {
            if (result.output=="success") {
                sum += result.balance;
            }
            console.log("Sum : " + sum)
        });
   });
}).then(function(){
    console.log("All Loops Completed");
});
console.log(sum);
When I run above code sequence of consoles are
Completed Fetching List of vendors,
All Loops Completed,
Sum,
Sum,    
Sum....
But I need then to be
Completed Fetching List of vendors,
Sum,
Sum,
Sum....,
All Loops Completed
What modifications should be done in above code to achieve desired result ? I tried using $.each(...).promise().done() but no success. Any Help would be appreciated.
