Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

fetch CSV skipping header

I’ve a simple function for read a csv file and works good! but i want to skip the header and start to use it from 2nd line

CSV

| date              | open    | high    | close  | low     | volume  |
+───────────────────+─────────+─────────+────────+─────────+─────────+
| 2022-05-15 18:00  | 25.652  | 33.451  | 26.185 | 23.146  | 486.651 |

JS
`

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const getData = async () => {
    const res   = await fetch('data.csv');
    const resp  = await res.text();
    const cdata = resp.split('\n').map((row) => {
      const [date, open, high, low, close, volume] = row.split(',');
      return {
        date:   date,
        open:   open,
        high:   high,
        low:    low,
        close:  close,
        volume: volume,
      };
    });
    return cdata;
    //   console.log(cdata);
  };

`

>Solution :

Just do .split('\n').slice(1).map((row) => {

const data = `col1,col2
1,2
3,4`

console.log(data.split('\n').slice(1))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading