I'm using the following function to sort an object by keys.
The problem is when I have to sort '05' and '10', the '10' is sorted before the '05'
function sortObj(obj) {
return Object.keys(obj).sort().reduce(function(result, key) {
result[key] = obj[key];
return result;
}, {});
}
let list = {
'10': "Ann",
'05': 75
};
let arr = sortObj(list);
console.log(arr);
Object { "10": 75, "05": "Ann" }