I'm new to Javascript and I'm trying to create an array to use for Autocomplete plugin. The plugin is working perfectly with the following code:
countries = new Array();
countries[0]='United States';
'use strict';
$('#autocomplete').autocomplete({
lookup: countries,
minChars: 2,
onSelect: function (suggestion) {
//I will put something here soon.
}
});
But when I try to create an array from a text file, I can't create the array even though the code seems fine.
$.get('test.txt', function(data){
var array = data.split(',');
var i = 0;
array.forEach(function(insert) {
countries[i]=insert;
i++;
});
});
Any reason why it would not insert the data in the text file to the countries array? It seems to me that everything I do should work. By the way, no worries, the test.txt file is just fine (United States,Mexico).
Thanks ahead and have a great day.