-1

I am coding in JavaScript, and I am using AJAX to open up a file. It opens up the file fine, and I can read the file. But it is a comma separated file with many lines. The problem is that the .responseText property of that object covers ALL of the text within the file.

What I need is for it to give it to me one line at a time, so I can split the records and process the file accordingly.

Anyone know how to do this?

Chase
  • 31
  • 4
  • Duplicate: [How can I parse a CSV string with Javascript?](http://stackoverflow.com/questions/8493195/how-can-i-parse-a-csv-string-with-javascript) – Yogi Apr 01 '16 at 18:31

1 Answers1

0

To split a string on line breaks, use split:

var lines = str.split('\n');

Since you mentioned your file is comma separated, you can then get each of the values by using split(','):

lines.forEach(function(line) {
  var values = line.split(',');
  // do stuff
});
Mike Cluck
  • 31,869
  • 13
  • 80
  • 91