Is PapaParse adding an empty string to the end of its data array?
Asked Answered
A

3

20

Papa Parse seems wise, but I think he might be giving me null. I'm just:

 Papa.parse(countries);

Where countries is a string containing the XMLHttpRequest of the countries csv file from a timezone database here: https://timezonedb.com/download

But Papa Parse seems to have added an empty array to the end of it's data array. So when I'm searching and sorting through the array, that one empty guy at the end is giving me troubles. I can write around it but it's not ideal, and I thought Papa Parse was supposed to make those kind of csv parsing problems go away. Am I Parsing wrong?

Here is the end of the PapaParsed Array in console: Papa why?

Adala answered 30/1, 2017 at 19:43 Comment(0)
F
37

You need to use skipEmptyLines: true in parse config. For example:

Papa.parse(this.csvData, {skipEmptyLines: true,})
Folse answered 29/9, 2017 at 20:2 Comment(0)
S
1

it was adding empty line to my iteration as well. i decided to skip it by doing loop:

for(let i=0;i<data.length -1;i++){
Seignior answered 2/2, 2017 at 11:6 Comment(1)
I did something similar, by checking if each entry was emptyAdala
B
0

We can also use below syntax to remove empty lines from the record.

For example, in order to remove empty values from header, we can use the below code snippet.

headers.filter(Boolean);
Basifixed answered 12/5, 2020 at 4:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.