I have two nested each loops like so.
$.each(a, function(index1, value1){
console.log(value1)
$.each(b, function(index2, value2){
console.log(value2);
}
}
The output I'm expecting is
a0
b0
b1
b2
a1
b0
b1
b2
etc
But what I'm actually getting is
a0
a1
a2
b0
b1
b2
etc
How do I achieve the output I want. I understand that deferred objects are implemented now and that I can define functions and execution using deferred objects on functions I declare but I'm unsure on how to do that on existing functions.
EDIT: I messed up and abstracted it too much.
getAByX(x, function () {
$.each(A, function (index, value) {
full_list += "string with info";
full_list += table_header;
getBByA(value, function () {
$.each(B, function (index2, value2) {
full_list += "string with info";
});
});
});
$(".table").append(full_list);
hideLoading();
});
Here's the trimmed full code, it's the function calls that are messing things up, $.each loops execute synchronously.
EDIT 2: Fixed the errors in the original short piece of code. Also, since the first piece of code works that means that the $.each loops execute synchronously and it's the function calls that I made that execute asynchronously. This realization makes the initial question invalid since the $.each call has the appropriate behavior.