Reputation: 47
I successfully am generating a CSV using Javascript. I want to have two lines in the final CSV - one header and one data line.
Here is my code for generating the header.
var csvContent = "data:text/csv;charset=utf-8,participant_id,age,gender,country_live_longest,country_musical_enculturation,lyric_language,favorite_genre,years_formal_training,understood_yes_or_no,media_shown,";
for (var i = 0; i < randomized.length; i++) {
csvContent += "arousals_"+ i.toString() +",valences_"+ i.toString() +","
}
csvContent = csvContent.slice(0, -1);
csvContent += '\r\n';
After this it's a simple string append with comma separated values. However, when I check the string getting built it stops being downloadable after the new line or after any spaces.
This is what it looks like in console.
Anything in red is not part of the CSV downloadable file.
What should I do to fix this issue?
Thanks!
Upvotes: 0
Views: 119
Reputation: 189
Try using blob API https://developer.mozilla.org/en-US/docs/Web/API/Blob. Here is an example Convert JavaScript variable value to csv file
Upvotes: 1