I have array created from JSON, and I want to create new options in my select. I do not have any errors, and I don't know what's wrong with my code. In HTML I have:
<select class="currencyList">
</select>
And in JS:
var currencyList = [];
$(document).ready(function() {
getCurrencies();
createOptions();
});
function getCurrencies() {
$.getJSON(
"http://api.nbp.pl/api/exchangerates/tables/a/?format=json",
function(response) {
$.each(response[0].rates, function(i, item) {
currencyList.push(item);
});
}
);
}
function createOptions() {
var option = "";
for (var i = 0; i < currencyList.length; i++) {
option += "<option value='" + currencyList[i].code + "'>" + currencyList[i].currency + "</option>";
}
$(".currencyList").append(option);
}
I can access data in the array from the console.