0

I have one CSV file in my project and I want to parse it using jquery mobile or javascript. I want to parse my local CSV file into primitive array and display it in a listview. I have tried CSVtoArray and other similar functions but it was of no help.

Would be grateful if you could help me with my problem - may be some sample code or some useful links.

viral
  • 4,168
  • 5
  • 43
  • 68
Anil
  • 1,028
  • 9
  • 20
  • The simplest way I can think of is: Splitting the rows into an array: `rows = csv.split('\n')` and then split each row into another array (in a loop!) with: `row = rows[c].split(',')`; – olsn Mar 25 '13 at 09:14
  • 1
    You said you had trouble turning an CSV into an Array for parsing, this can be done with two simple split-operations, and you'll get a multi-dimensional Array. And just as a side-note: While it is possible that I got your question wrong - You still shouldn't say stuff like "what the hell" to people who are trying to help you. – olsn Mar 25 '13 at 09:20
  • Ok. But, can you post some detailed code (of some few lines)that I can implement? – Anil Mar 25 '13 at 09:24
  • http://stackoverflow.com/questions/1293147/javascript-code-to-parse-csv-data – olsn Mar 25 '13 at 09:27
  • If the CSV file is static and you don't have to parse any other CSV data from remote sources it might be better to convert the file to JS as part of your build process. – Vlad Stirbu Mar 25 '13 at 13:11
  • @olsn can you post your first comment as an answer so that i can accept it as an answer? – Anil Apr 05 '13 at 13:35

1 Answers1

2

The simplest way I can think of is: Splitting the rows into an array: rows = csv.split('\n') and then split each row into another array (in a loop) with: row = rows[c].split(',')

For a very detailed algorithm, refere to this answer: Javascript code to parse CSV data

Community
  • 1
  • 1
olsn
  • 16,644
  • 6
  • 59
  • 65