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

297
Visualizações
How can I read 2 CSV files in vanilla HTML/JS and combine their data?

I am writing a program that takes in a number of csv files (for this example's sake I chose 2), does some calculations, and then returns a csv file at the end.

I am currently able to read a single file thanks to the addEventListener but I can't figure out how to get the the information from the file outside the function that I pass into addEvenListener (the function is called test in the code).

I am a bit of a beginner when it comes to all of this so I am not sure that this is the optimal solution. I am open to other solutions/approaches in vanilla Javascript as this will only be run locally.

Here is the code:

function getData() {
  
  const tritonReader = new FileReader(); //the first file reader
  const [triton] = document.querySelector('#Triton').files;
  
  const freewheelReader = new FileReader(); //the second file reader
  const [freewheel] = document.querySelector('#Freewheel').files;
  
  var tritonRevenues = [[0,0],[0,0],[0,0]];

  function test() {
    var tritonString = tritonReader.result;

    const rows = tritonString.split('\n').slice(1); //creating an array with the rows, splitting by line break

    tritonRevenues = get2DArray(rows, ","); //creates the 2d array from the previous array (rows)
    var bla = createTritonRev(tritonRevenues);//does the calculations I need and returns the final array
    
    //result_csv = arrayToCsv(finalArray); //turns the array into a string formatted as a csv
    //downloadBlob(result_csv, 'Revenues.csv', 'text/csv;charset=utf-8;') //creates the csv file from the string
  
  }
  
  tritonReader.addEventListener("load", test, false); //adds the event listener to read the file 

  if (triton) { 
    tritonReader.readAsText(triton);
  }
  
  if (freewheel) {
    freewheelReader.readAsText(freewheel);
  }

}```
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