Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
Javascript: cargue datos de un conjunto de datos csv local en una matriz 2d en una función y luego pueda repetir esa matriz en otra función

Mi problema está relacionado con el archivo javascript y csv. El archivo cvs es de un Excel y se encuentra en el lado del servidor. Mi objetivo final es poder hacer algunas estadísticas con estos datos...

Probé diferentes métodos usando papaparse, csv-parser y recibí algunos errores.

la siguiente manera parece tener algún problema:

Utilicé una función asíncrona getData() para convertirla en una matriz 2d y está funcionando:

 const rep=await fetch('datan2.csv') const data=await rep.text(); let fin=[] const table=data.split('\n').slice(1) table.forEach(row=>{ const colums=row.split(','); tab=[colums[0], colums[1],colums[2]] fin.push(tab) }); return fin } ``` From the following code, I can easily loop the array **fin** The problem now is when I try to get this array outside this function: for example in the following code, where printing **t** is working but I cannot access a specific element of the array: ```t=getData() console.log(t)//working console.log(t[0][0])// not working here``` Can someone help? because my final goal is to be able to loop the array out side the **getData** method. Thanks
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Intente reemplazar forEach con For..of . Al igual que

Reemplazar

 table.forEach(row=>{ const colums=row.split(','); tab=[colums[0], colums[1],colums[2]] fin.push(tab) });

Con

 for(const row of table){ const colums=row.split(','); tab=[colums[0], colums[1],colums[2]] fin.push(tab) }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!