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

106
Visualizações
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 à 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