Sorting by key doesn't work if it has "0"
const resObj = { '15': 686, '03': 598, '14': 803, '16': 1000, "04": 123 };
const resData = Object.entries(resObj).sort(([a,], [b,]) => a - b)
.reduce((o, [k, v]) => ({...o, [k]: v}), {})
output:
{ '14': 803, '15': 686, '16': 1000, '03': 598, '04': 123 }
And when "0" is not in the key, it will work
const resObj = { '15': 686, '13': 598, '14': 803, '16': 1000, '17': 123 };
output:
{ '13': 598, '14': 803, '15': 686, '16': 1000, '17': 123 }
Could someone please explain why it become that way