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

100
Visualizações
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 à 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