I have a list like this one (it is already proper sorted in php)
myList = {
"394":"Andres",
"388":"Franck",
"380":"John",
"415":"Philip"
}
But if I use data = JSON.parse(myList) to make an object for dropdown, as respons I am getting list automatically sorted by keys what actually I do not want.
Result:
data = {
"380":"John",
"388":"Franck",
"394":"Andres",
"415":"Philip"
}
So what is the best way to make sort on list as JSON object to get list sorted by values?
I have tried:
var keyList = Object.keys(data).sort(function(a,b){return data[a]-data[b]});
var valueLIst = Object.values(data).sort(function(a,b){return data[a]-data[b]});
var obj = {};
for(var i=0,len=keyList.length; i < len ;i++) {
obj[keyList[i]] = valueLIst[i];
}