Sort keys in an object by the value of the property
$ npm install --save sort-keys-by-value
const sortKeysByValue = require('sort-keys-by-value');
sortKeysByValue({ a: 2, b: 2, c: 1, d: 3 });
//=> { c: 1, a: 2, b: 2, d: 3 }
sortKeysByValue({ a: 2, b: 2, c: 1, d: 3 }, { reverse: true });
//=> { d: 3, a: 2, b: 2, c: 1 }
sortKeysByValue({ a: 2, b: 2, c: 1, d: 3 }, { reverse: true, reverseKey: true });
//=> { d: 3, b: 2, a: 2, c: 1 }
Returns a new object with sorted keys based on value of properties.
Type: Object
Type: boolean
Sorts by descending value of property
Type: boolean
Where two properties have the same value, sort the keys in reverse order
ISC © Navdeep Singh