addedlovely
addedlovely

Reputation: 3194

Convert CSV to multi dimensional array in Javascript

I'm reading data from a CSV file using jQuery's Ajax function. I have been using a Jquery plugin called Jquery CSV to convert the data into an array, but in Internet Explorer the array is returning different keys for some reason.

The code for the ajax call and the plugin processing the data was:

var ourOffices = new Array();
$.get(pathToData, function(data) {
   ourOffices = jQuery.csv("|")(data);
});

Can someone point me in the right direction to coding this conversion without a plug in.

The fields are separated by '|' . Each record is on a new line, of which there are 300. Also of note, which might be why the first plugin misbehaves, is that some of the data in the CSV contain special characters, like accents.

Thanks.

p.s. I would supply some example data, but its not appropriate to do so, sorry.

Upvotes: 2

Views: 2729

Answers (1)

millebii
millebii

Reputation: 1287

I'm sure you have seen the comment in the plugin split() doesn't work properly on IE. "a,,b".split(",") returns ["a", "b"] and not ["a", "", "b"] could that be your issue.

Upvotes: 3

Related Questions