I used sortBy function in underscore.js library.
I have hash, and I tried to sort it by value as the following:
var obj = {x: 2, y: 6, z: 1, q: 4};
_.sortBy(obj)
But the output is as the following:
[1, 2, 4, 6]
But I need to sort it, and return keys with value as the following:
{z: 1, x: 2, q: 4, y: 6}
How can I return sorted hash using sortBy
?
I noticed that sortBy
function return list, so is there another good solution to sort hash or I need to implement function return sorted hash ?