1

How can I open a .csv file and turn values into a javascript array.

In classical programming i'd do this by:

  1. opening the file as a string
  2. splitting by ,
  3. close the file

I know how to split, .split(','), but how do I open and close the csv file in javascript or jquery?

gariepy
  • 3,518
  • 5
  • 20
  • 34
MrGuru
  • 325
  • 5
  • 15

1 Answers1

2
$.get(url,function(data)
    {
        var MainArray = data.split('\n');
        for(var i=0;i<MainArray.length;i++)
        {
            MainArray[i] = MainArray[i].split(',');
            // now MainArray is a two dimensional array that contains csv file 
            //MainArray[row index][column index]
        }
    }
);
Ashkan Mobayen Khiabani
  • 32,319
  • 30
  • 98
  • 161