My question is about fetching and sorting data (which includes accented words) before populating a "select" field on my application.
This is my code for fetching and populating a list of states (that are being sorted by their id's, and not by their names):
function populateUFs() {
const ufSelect = document.querySelector("select[name=uf]")
fetch("https://servicodados.ibge.gov.br/api/v1/localidades/estados")
// .then( (res) => { return res.json() })
.then(res => res.json())
.then(states => {
for (const state of states) {
ufSelect.innerHTML += `<option value="${state.id}">${state.nome}</option>`
}
})
}
populateUFs()
<select name="uf">
</select>
How could I sort the list of states in alphabetic order, considering accented words please?
i.e.:
- São Paulo
- Santa Catarina
- Tocantins
and not:
- São Paulo
- Amapá
- Amazonas
Thanks.