Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading .txt file into array Javascript/jQuery

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!

like image 209
spogebob92 Avatar asked Jun 15 '26 21:06

spogebob92


1 Answers

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

like image 114
Chris Hughes Avatar answered Jun 18 '26 10:06

Chris Hughes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!