Hold Down! before marking as duplicate or voting down
let's say I have a java Script Object as below and I wanna to sort this object by values, yes I know array is invented for it and has builtin sort
but for some reason I have to go with this object :(
var myObj = {"you": 100, "me": 75,"11111": 20, "foo": 116, "bar": 15};
till now I end up with
{11111: 20, bar: 15, me: 75, you: 100, foo: 116}
but you can see it's not what you want, as in that case, I tried many solution from this deprived solution given here the code is below
Object
.keys(myObj)
.sort((a, b) => myObj[a]-myObj[b])
.reduce((_sortedObj, key) => ({
..._sortedObj,
[key]: myObj[key]
}), {})
Edit I see this question already it's not my case as I have numeric values so not any single answer given there helpful for me