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

110
Vistas
Is there a way to check if headers exist on a CSV in javascript/typescript?

I'm given a CSV that contains many rows. This CSV may or may not contain a header. E.g.

Column Name 1,Column Name 2
data1,data2
data3,data4
data5,data6
...

My goal is to extract the leftmost column into an array, which I can do by doing this

const column = csv
.split('\n')
.filter(r => r)
.map(r => r.split(',')[column]?.trim())
.slice(1);

This would return

['data1', 'data3', 'data5']

My issue is that this is assuming that the CSV has a header - I slice(1) the header out of the solution. If I were given a CSV without a header, I would accidentally omit the 0th row.

Is there a way to check if headers exist, or a better solution to this problem in general?

about 4 years ago · Juan Pablo Isaza
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