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

274
Vistas
Convert Papaparse rows to objects

Does papaparse support return an array of object instances that are keyed by the header columns?

For example I have a CSV file like this:

sku, location, quantity
'sku1', 'Chicago', 3
'sku2', 'New York, 4

I'd like the array returned by papaparse to look like this:

 [{sku: 'sku1', location: 'Chicago', quantity: 3}, ...]

This should also be possible:

results[0].sku == 'sku1'
results[1].quantity == 4
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Try adding header: true to the config parameter.

From the docs:

header: If true, the first row of parsed data will be interpreted as field names. An array of field names will be returned in meta, and each row of data will be an object of values keyed by field name instead of a simple array. Rows with a different number of fields from the header row will produce an error. Warning: Duplicate field names will overwrite values in previous fields having the same name.

For example:

Papa.parse('./data.csv', {
  download: true,
  header: true, // gives us an array of objects
  dynamicTyping: true,
  complete: ({ data }) => console.log(data),
});

given your data should yield

[
  {
    sku: 'sku1',
    location: 'Chicago',
    quantity: 3,
  },
  {
    sku: 'sku2',
    location: 'New York',
    quantity: 4,
  },
]
over 4 years ago · Santiago Trujillo Denunciar

0

It is possible by few line in simple javascript working example:

My csv file data:

sku, location, quantity

'sku1', 'Chicago', 3

'sku2', 'New Yoark, 4
over 4 years ago · Santiago Trujillo Denunciar
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