Loading an array from .txt file

前端 未结 2 858
伪装坚强ぢ
伪装坚强ぢ 2021-01-15 13:45

I need to load an array from a .txt file. It has few strings separated by commas (,).

So far I have found this.

That guy splits it with .split

相关标签:
2条回答
  • 2021-01-15 14:18

    You can read html files locally since html5. Check the html5 API and some examples here. Then use Alexanders answer to parse it.

    EDIT: here and here are some good and short examples on how to use it.

    0 讨论(0)
  • 2021-01-15 14:27

    Just make sure the text file is accessible through an HTTP request on the same domain and you can read it fine. Here's an example where the text file is located in the webroot.

        $(function(){
            $.get('/whatever.txt', function(data){
                var array = data.split(',');
                console.log(array);
            });
        });
    
    0 讨论(0)
提交回复
热议问题