I have the following json data:
{
"324": "Aguacate",
"196": "Fresa",
"7875": "Mandarina",
"197": "Platano",
"9517": "Uvas"
}
For any reason, when I populate the target select dropdown's options, it returns the options in a different order (by ID):
{
"196": "Fresa",
"197": "Platano",
"324": "Aguacate",
"7875": "Mandarina",
"9517": "Uvas"
}
Considering that the script looks like:
$.getJSON("http://path/to/blabla.json", customfunction);
function customfunction(data) {
var $select = $('#mymail_data_socio');
// First, empty the select field
$select.find('option').remove();
$.each(data,function(key, value) {
$select.append('<option value=' + key + '>' + value + '</option>');
});
}
Is there any way to return the options in the same order as in my json file? How I should rewrite my script in order to achieve it?
Thanks!