I am trying to convert a text file into a js array using the line separation. Here is a copy of my code, can someone help?
getData('test.txt', 'text', handleSuccess);
function handleSuccess(data) {
intoArray(data);
}
function intoArray(lines) {
lineArr = lines.split('\n');
}
function createXMLHttpRequest() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
function getData(url, responseType, successHandler) {
var xmlhttp = createXMLHttpRequest();
xmlhttp.responseType = responseType;
xmlhttp.onreadystatechange = function() {
successHandler(xmlhttp.response, xmlhttp.statusText, xmlhttp);
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
console.log(lineArr);
And here is a copy of the text document I have:
newsletter.pdf
newsletter
flyer.pdf
flyer
The console log returns an empty array. Any Ideas?