I'm trying to fetch data from a local JSON file, here is the JS script so far
let accordion=document.querySelector('#accordion');
fetch('countries.json')
.then(function(response){
return response.json();
})
.then(function(data){
let continents=Object.keys(data);
for(let i=0;i<continents.length;i++){
let continent=continents[i];
let heading=document.createElement('h3');
heading.textContent=continent;
accordion.appendChild(heading);
let countries=data[continent];
let ul=document.createElement('ul');
for(let j=0;j<countries.length;j++){
let country=countries[j];
let li=document.createElement('li');
li.textContent=country;
ul.appendChild(li);
}
accordion.appendChild(ul);
}
})
What it does is it shows the header of the data "continents" and the number of rows just fine, but whatever inside the array (which all of the content really) shows up as [Object Object], so I need to fetch this data properly and also the data inside the array objects.
Turns out it was a simple solution... as referred by Bammar, I mislabeled my data
Something like li.textContent = country.name
BTW country turned out to callback continents actually, so that's fixed and by forEach loops, I'll be fetching country data.