将.txt文件读入数组Javascript / jQuery [英] Reading .txt file into array Javascript/jQuery

查看:71
本文介绍了将.txt文件读入数组Javascript / jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文件(存储在Web服务器上)读入数组。当我打印数组时,我目前得到未定义。以下是使用的代码:

I am trying to read a file (stored on the web server) into an array. When I print the array I currently get "undefined". Here is the code im using:

var cardRules = new Array;
    $.get('UserFile.txt', function(data){
            var array = data.split('\n');
            console.log(cardRules);
        });

任何帮助都将不胜感激!

Any help would be appreciated!

推荐答案

'cardRules'变量永远不会被数组数据填充。而不是
var array = data.split('\ n');
只需使用
cardRules = data.split('\ n');

The 'cardRules' variable never gets populated with the array data. Instead of var array = data.split('\n'); just use cardRules = data.split('\n');

这篇关于将.txt文件读入数组Javascript / jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆