Before I ask; there are a bunch of discussions on this particular subject, most of which pertain to ES5 and do not necessarily hold truth for ES6. I'm attempting to get some clarification, and maybe help the next person that is scouring the internet for an answer. This is in reference to ES6 specifically.
QUESTIONS:
Consider the following object structure:
const unsorted_object = {
'C': '0003',
'D': '0004',
'A': '0001',
'B': '0002',
'F': '0005',
};
How can I sort a JavaScript object by key? (Answered here)
const sorted_object = {}; Object.keys(unsorted_object).sort().forEach(function(key) { sorted_object[key] = unsorted_object[key]; });
How can I sort a JavaScript object by the key value?
EDIT #1
I might not have been totally clear on question #2. The idea is to sort the JavaScript object by the value of the key, not by key and value.
EDIT #2
const unsorted_object = {
'0001': '13.1666',
'0002': '11.0001',
'0003': '10.6664',
'0004': '13.1666',
'0005': '7.3331',
};
Output:
'0001': '13.1666' '0004': '13.1666' '0002': '11.0001' '0003': '10.6664' '0005': '7.3331'