2

I am trying to parse a simple csv file in javascript. I've seen some questions in Stackoverflow, but the solutions are having a input field in the html body. But I want to read the data from local disk directly in the javascript. I've googled and found some scripts like papaparse, jquery.csv. But couldn't find the logic to load the file into javascript. Below is the code that I tried with papaparse.js

var file = new File([""], "TweetSource.txt");
var ts = Papa.parse(file, {
    header: false,
    delimiter: ",",
    dynamicTyping: true
    complete: function(results) {
        var data = results;
        return data;
});

The code is not loading the text file. Also, I'm confused with the later steps (how to go through the ts variable)

Please help me.

Thanks.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • To read a file on the local machine use the `FileReader` API: https://developer.mozilla.org/en/docs/Web/API/FileReader – Rory McCrossan Nov 13 '16 at 21:39
  • 3
    *"read data directly from local disk"* .. if environment is browser you can't without user interaction to select the files using an input or drag/drop – charlietfl Nov 13 '16 at 22:05

0 Answers0