http://codepen.io/noczesc/pen/ZWppJQ?
function codeToName(data) {
for (var i = 0; i < data.country.borders.length; i++) {
$.getJSON("https://restcountries.eu/rest/v1/alpha?codes=" + data.country.borders[i], function(json) {
data.country.borders[i] = json[0].name;
console.log(json[0].name);
});
}
};
I'm getting an array of country codes which are supposed to be changed to their full representations in English via the codeToName loop and an API, but it only appends a random name to the end of the array. To get a console.log of it, click on the <body>. It's located in JSONextract.country.borders. The country names grabbed via API are correct (logged in console also), but they don't get assigned to the variables inside my object. How can I solve this issue?