I'm trying to set up a currency converter application for a web page. I'm using an API and the response I get are the variables in alphabetical order, but I'm understanding that using a for...in loop will arbitrarily get me the variables I'm looking for. Is there a way to order them alphabetically after I get them while keeping the same for...in structure?
function loadCurrency(){
let from = document.getElementById('from');
let to = document.getElementById('to');
let xHttp = new XMLHttpRequest();
xHttp.onreadystatechange = function(){
if(xHttp.readyState === 4 && xHttp.status === 200) {
let obj = JSON.parse(this.responseText);
let options = '';
for(key in obj.rates){
options = options+'<option>'+key+'</option>';
}
from.innerHTML = options;
to.innerHTML = options;
}
};
xHttp.open('GET','https://api.exchangeratesapi.io/latest',true);
xHttp.send();
}