3.0.2 • Published 6 years ago
ckeys v3.0.2
ckeys
Return a compare function (to compare object's keys) to use in an Array's
.sort()
function
Installation
$ npm install --save ckeys
Usage
ckeys(key)
var ckeys = require('ckeys')
var array = [
{text: 'a', num: 7},
{text: 'b', num: 1},
{text: 'c', num: 23},
{text: 'd', num: 79}
]
array.sort(ckeys('num'))
/*
[ { text: 'b', num: 1 },
{ text: 'a', num: 7 },
{ text: 'c', num: 23 },
{ text: 'd', num: 79 } ]
*/
array.sort(ckeys('num', true))
/*
[ { text: 'd', num: 79 },
{ text: 'c', num: 23 },
{ text: 'a', num: 7 },
{ text: 'b', num: 1 } ]
*/