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

101
Vistas
How to fetch multiple files synchroniously and load them into a single variable

How would you recommend I go about fetching multiple files (in particular, CSV files) and merging them into a single variable? I've tried using the following and I'm pretty sure I got something about the promise syntax/logic wrong, as that is an area I'm fairly new to, but it may be another problem. Here is my current attempt:

fetcher(specURL).then(async (spec) => {
    let rawData;
    if (typeof spec.dataURL === "string") {
        rawData = await fetcher(spec.dataURL);
    } else if (typeof spec.dataURL === "array") {
        rawData = {};
        await spec.dataURL.forEach(async (url, i) => {
            rawData[i] = await fetcher(url);
        });
    }
    console.log(rawData);
}

As you can see I use a spec (specification) json which articulates which URLs to fetch. If it is an array I would like to fetch multiple files into an array.

I'm using my fetcher function, which is the following (any recommendations to improving it are appreciated too!

async function fetcher(url, type) {
let fetched = await fetch(url);
fetched = await fetched.text();
if (type == undefined) {
    type = url.split(".").pop();
}
if (type == "json") {
    fetched = JSON.parse(fetched);
} else if (type == "csv") {
    fetched = Papa.parse(fetched, { header: true }).data;
}
return fetched;

}

about 4 years ago · Juan Pablo Isaza
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