sort-keys-by-value

0.1.1 • Public • Published

sort-keys-by-value Build Status

Sort keys in an object by the value of the property

Install

$ npm install --save sort-keys-by-value

Usage

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 }

API

sortKeysByValue(input, [options])

Returns a new object with sorted keys based on value of properties.

input

Type: Object

options

reverse

Type: boolean

Sorts by descending value of property

reverseKey

Type: boolean

Where two properties have the same value, sort the keys in reverse order

License

ISC © Navdeep Singh

/sort-keys-by-value/

    Package Sidebar

    Install

    npm i sort-keys-by-value

    Weekly Downloads

    1

    Version

    0.1.1

    License

    ISC

    Last publish

    Collaborators

    • navdeepsinghkhalsa