I am experiencing an issue with my array of 10 elements. When I log their key, value pairs in a loop, they are correctly ordered.
$.each( sArray, function(i, k) {
log(i, k);
// log(i, k) returns correctly
// [0] ELEMENT ONE
// [1] ELEMENT TWO
// [2] ELEMENT THREE
});
However, when I add an $.ajax
call and try to log the array from there, the indices return in a random order (the order changes every time the page is refreshed)
$.each( sArray, function(i, k) {
$.ajax({
success: function(data){
log(i, k);
// returns unordered
// [2] ELEMENT TWO
// [1] ELEMENT ONE
// [3] ELEMENT THREE
// [5] ELEMENT FIVE
// [4] ELEMENT FOUR
// etc...
}
});
});
The key, value pairs match, but the order is unpredictable. Can someone clarify this behavior? Thank you!