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

157
Views
Tengo un error al convertir CSV a Array

¿Hay alguna forma de corregir este error de CSV después de convertir un CSV en una matriz? Consola registra los objetos en la matriz, la última propiedad tiene un error

Código

 const csvFileToArray = (string, delimiter = ",") => { const csvHeader = string .slice(0, string.indexOf("\n")) .split(delimiter); const csvRows = string.slice(string.indexOf("\n") + 1).split("\n"); const array = csvRows.map((row) => { const values = row.split(delimiter); const obj = csvHeader.reduce((object, header, index) => { object[header] = values[index]; return object; }, {}); console.log(obj) return obj; }); localStorage.setItem("bulkUpload", JSON.stringify(array)); handleClose(); return setArray(array); };

Producción

 { "category": "5f1a2779-f4b7-4e0d-a8fd-d2fff7e04418", "name": "product", "bulk_image": "image_url", "quantity": "18", "currency": "USD", "vendor": "815c5741-ed74-454f-85cd-c8f0a1aeee64", "price\r": "1399\r" }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La solución de Phuzi funcionó. Terminar con un solo \n fue el problema. Debe terminar con \r\n .

Aquí está el código correcto

 const csvHeader = string .slice(0, string.indexOf("\r\n")) .split(delimiter); const csvRows = string.slice(string.indexOf("\r\n") + 1).split("\r\n");
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!