i'm currently attempting to load data from a text file into an array using ajax, and this is the code i am utilizing:
function loadWords(){
var xhr = new XMLHttpRequest();
xhr.open('GET', "dico/francais.html");
xhr.onreadystatechange = function(){
if(xhr.readyState == xhr.DONE && xhr.status == 200){
dico = xhr.responseText.split("\n");
for(var i=0; i<wordsNBR; i++){
var x = Math.floor(Math.random()*dico.length);
words[i] = dico[x];
}
}
}
xhr.send(null);
}
the original code works as expected. However, when attempting to modify the following portion:
for(var i=0; i<wordsNBR; i++){
var x = Math.floor(Math.random()*dico.length);
words.push(dico.splice(x,1));
}
I encounter an issue where it no longer functions as intended. Does anyone have any insight into why this may be happening?