For example the following
var data = {
\'States\': [\'NSW\', \'VIC\'],
\'Countries\': [\'GBR\', \'AUS\'],
\'Capitals\': [\'SYD\', \'MEL\']
}
for
here's a nice functional solution:
basically,
Object.keyssort the keysES5 Solution:
not_sorted = {b: false, a: true};
sorted = Object.keys(not_sorted)
.sort()
.reduce(function (acc, key) {
acc[key] = not_sorted[key];
return acc;
}, {});
console.log(sorted) //{a: true, b: false}
ES6 Solution:
not_sorted = {b: false, a: true}
sorted = Object.keys(not_sorted)
.sort()
.reduce((acc, key) => ({
...acc, [key]: not_sorted[key]
}), {})
console.log(sorted) //{a: true, b: false}