I have made the following function for getting data from my database.
function getData() {
var array = [];
var clickBtnValue = "getInteractive";
var ajaxurl = '../crawler/function/statistic_func.php',
data = {'action': clickBtnValue, 'intervalHour': "1", 'value': "main_tag", 'valueEqualTo': searchTag};
$.get(ajaxurl, data, function (response) {
// Response div goes here.
objIntChart = JSON.parse(response);
objIntChart.forEach(function (entry) {
array.push([entry['dateTime'], entry['entries']]);
});
console.log(array);
});
console.log(array);
return array;
}
My first console.log(array);
prints out the array exactly how it is supposed to be.
The second console.log(array);
prints out an empty array. I am not sure why this is the case when I have initialised the array in the beginning of the function?