how to create an array by reading text file in javascript

后端 未结 5 1146
日久生厌
日久生厌 2020-12-22 08:35

I have a text file with profanity word separated by comma (,). Now I have to create an array by reading this text file, each and every profanity word should be stored into t

5条回答
  •  时光取名叫无心
    2020-12-22 09:26

    Are you able to manipulate the CSV file manually before reading it? I had a similar issue, but was able to get the person that generated it to do a few things to it such as doing a global search/replace for '\' then wrapping the contents in a JS string variable. Then I just included the new file as I would any other JS file.

    Ex.

    
    
    
    
    

    Original CSV:

    word,"multiple words",apostrophe's
    

    Modified JS CSV:

    var csvData = 'word,"multiple words",apostrophe\'s';
    

    And then I used the Ben Nadel link posted by samccone to do the actual parsing.

提交回复
热议问题