-1

I'm new, please have mercy. I am able to upload my csv and I can see that it is really there. I am able to get the filename and size but I want to get the contents. This is my current function for handling the user-uploaded csv:

uploadCsv: function(e) {
        var input = e.target;
        var file = input.files[0];
        var fd = new FormData();

        fd.append('Content-Type', file.type);
        fd.append('file', file);
    }

The contents of my csv file looks like this:

id,name,email,birthday,contact_number,blacklisted,is_vip,interests,total_spend,current_spend,total_points,created_at,updated_at
10645,action,action123@test.com,2001-01-05T00:00:00+0800,N,,0.00,24700,,2018-12-05T16:51:06+0800,2018-12-05T16:51:06+0800
10643,boy,meows@gmail.com,2001-01-05T00:00:00+0800,N,,0.00,,,2018-12-05T16:31:26+0800,2018-12-05T16:31:26+0800
10642,boy,test321@test.com,2001-01-05T00:00:00+0800,N,,0.00,,,2018-12-05T16:30:05+0800,2018-12-05T16:30:05+0800

How do I read it in a way that I can get all the data in the id column only and store it in an array? Thanks in advance!

Aditya Tiwari
  • 204
  • 4
  • 17
lemonille
  • 3
  • 5
  • This seems like a duplicate question, you can find your solution [here](https://stackoverflow.com/questions/7431268/how-to-read-data-from-csv-file-using-javascript) – Aditya Tiwari Mar 20 '19 at 06:37
  • Possible duplicate of [How to read data From \*.CSV file using javascript?](https://stackoverflow.com/questions/7431268/how-to-read-data-from-csv-file-using-javascript) – Djensen Mar 20 '19 at 06:38

1 Answers1

0

First split the uploaded csv into an array using newline as the delimiter.

Create a new empty array.

Iterate over the csv array, split each element again using comma as a delimiter and save this as an element of the new array.

After this process you will have a two dimensional array containing your spreadsheet which you can process as you desire.

Andy Upton
  • 11
  • 2