Soft object by keys Clear method
const sortObjectByKeys = (object) => Object.keys(object)
.sort()
.reduce(
(obj, key) => {
obj[key] = object[key]
return obj
},
{}
)
Unclear but elegant method
const sortObjectByKeys = (object, asc = true) => Object.fromEntries(
Object.entries(object).sort(([k1], [k2]) => k1 < k2 ^ !asc ? -1 : 1)
)