Loading an array from .txt file

前端 未结 2 889
伪装坚强ぢ
伪装坚强ぢ 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: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);
            });
        });
    

提交回复
热议问题