Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

278
Visualizações
How to fetch JSON subcategories?

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.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda