Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

280
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda