I've checked all of the available questions and I understand that there are some oddities when dealing with jQuery's $.each loops. I can't seem to get why a variable declared outside of that scope, but initialized within it would be lost as well. I'm not dealing with the DOM at the moment, just using getJSON to pull some data in and hand it off to other functions for later use.
This is all I'm trying to do, and am completely baffled.
function getJSONData(){
var ar = [];
$.getJSON('pathto.json', function(data){
$.each(data, function(k,v){
ar.push(k); // lots of data in ar
});
});
return ar; // ar is empty again.
}
Is there a clue for the clueless here? I've tried every permutation of 'this' I can think of, and initializing ar within the getJSON loop.
Many thanks!