When I load my page I try to insert values from my database into JS array using AJAX, and after that to get a random value.
var arrayen = [];
$.ajax({
type: 'POST',
url: 'getEnglishWords.php',
success: function(words){
words = JSON.parse(words);
for(var i = 0; i < 50; i++) {
arrayen.push(words[i].en);
}
},error: (error) => {
console.log(JSON.stringify(error));
}
});
console.log(arrayen.length);
When I run the page, its insert the values into the array (I checked in chrome console), but - the console.log
I have added in the bottom print 0. its look like the console.log
run before the AJAX run and makes the problem.
Edit: I try to split the arrayen[12]
into own array. its mean every charater to be in array row. so I do this:
console.log(arrayen);
var array = arrayen[12].split('');
and I got error: Cannot read property 'split' of undefined