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

403
Vistas
How to fetch multiple .json files with javascript?

I have multiple .json files and I want to fetch them so I can take information from them. Like user ID, name, salary... I know how to do one, but I need two of them like in const "urls", so I can take data from both of them cycle through It, and put them in HTML elements.

`

const urls = ["./fake-server/employees.json", "./fake-server/salaries.json"];

fetch("./fake-server/salaries.json").then(function (response) {
    return response.json();
})
    .then(function (data) {
        for (var i = 0; i < data.length; i++) {
            document.getElementById("data").innerHTML +=
               "Person with employee ID of " + "<span class='employee-id'>" + data[i].employeeId + "</span>" + " have salary of  " + "<span class='employee-salary'>" + data[i].salary + "</span>" + " $" + " <hr/> ";
        }
    })
    .catch(function (err) {
        console.log(err);
    });

`

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

@Nonik comment's is the way

const urls = ["./fake-server/employees.json", "./fake-server/salaries.json"];

const requests = urls.map(u=>fetch(u));

Promise.all(requests).then(responses => {
  responses.forEach(response => {
    cost data = response.json();

    for (var i = 0; i < data.length; i++) {
            document.getElementById("data").innerHTML +=
               "Person with employee ID of " + "<span class='employee-id'>" + data[i].employeeId + "</span>" + " have salary of  " + "<span class='employee-salary'>" + data[i].salary + "</span>" + " $" + " <hr/> ";
     }
   });

})
.catch(function (err) {
   console.log(err);
});;
    
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