0

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.

enter image description here

Anything in red is not part of the CSV downloadable file.

What should I do to fix this issue?

Thanks!

1
  • Replacing with just \n instead of \r\n didn't work Commented Jan 28, 2020 at 5:22

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.