The code does not work, I do not understand why. The console displays an empty linesArray array.

var linesArray = []; jQuery.get('words.txt', function(data) { linesArray = data.split(/\s+/); }, 'text'); console.log(linesArray); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

Content of words.txt file: 1 2 3

1 answer 1

Possible without jQuery:

 var xhr = new XMLHttpRequest(); xhr.open('GET', 'words.txt', false); xhr.send(); if (xhr.status == 200) { linesArray = data.split(/\s+/); console.log('words.txt >', linesArray); } 

Try it, and if it does not work, look in the network tab that comes in response to your request, or whether the request is executed