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

105
Views
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
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!