I´m using jquery get function to retrieve data from the server (Laravel application). The data is bysically an array of objects. Simplified the .js code looks like this:
$(function(){
var results = [];
var getIt = function(){
$.get('results', function(response){
$.each(response, function(index, value){
results.push(value);
});
});
};
getIt();
console.log(results.length);
});
But the console logs 0, so the array is empty; What is wrong with it. The array should be available to later functions. Thanks for advice.