I've never seen this before and can't think of a reason for it, so I thought I would see if you folks that have been at this longer me know what's going on. Here is a simplified example of the problem:
var dataArray = [];
var itemCount = 0;
$.getJSON("data.js", function(results) {
$.each(results, function(index) {
dataArray[itemCount] = results[index].Data;
itemCount++;
}
});
});
for (var i = 0; i < dataArray.length; i++)
{
//Do something.
}
If I run this, it doesn't enter the for loop to iterate through the array, and it says length is 0. I've also done dataArray.push(results[index].Data) with the same results. If I add:
alert(dataArray.length);
alert(dataArray.length);
before the for loop with nothing else in between them, the first alert shows 0, the second one shows the correct length, and then it enters the loop and shows that the array was constructed correctly. What is going on with this?