I am trying to loop through 2 json files. So I created function. The results of this function is being pushed in 'response' array. But when I try to log the length of the array, it returns 0. It seems that the array is empty but when I check my console, it show results.
Here's my current code:
var response = [];
function getJSON(server, orgid) {
const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://pr.site.workers.dev/?'+server);
xhr.responseType = 'json';
xhr.onload = function(e) {
b = xhr.response
for (var i in b){
response.push([b[i]][0]);
}
};
xhr.send();
}
$(document).ready(function() {
arone = getJSON('https://www.chamberorganizer.com/members/mem_xml/BLVR_members.json','');
artwo = getJSON('https://www.chamberorganizer.com/members/mem_xml/SFCC_members.json','')
console.log(response);
Here's the result of the array: array collapsed array expanded with results