var array = ['a', 'b', 'c'], arrayLength = array.length, completed = 0;
Then in your XHR callbacks
if (completed == arrayLength) { // All of them have finished. } completed++;
Alternatively, you indicate that you are adding things to the new array. Assuming the arrays will be the same length upon completion, you can change the callback check to (startArray.length == newArray.length) .
Also, keep in mind that if you do XHR (assuming asynchronous) in a loop, they will all try to query at about the same time (I think), which could be a performance issue. Consider writing a function that is called again for each individual request callback, so XHRs are created one at a time. Increase the counter so you can index the next element of the array in each call.
source share