15

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?

kidconcept
  • 509
  • 6
  • 13

3 Answers3

28

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

Papa.parse(this.csvData, {skipEmptyLines: true,})
taras
  • 6,566
  • 10
  • 39
  • 50
Alex Fomushkin
  • 336
  • 4
  • 6
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++){
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);
NS23
  • 684
  • 5
  • 14