sort-of
Sort objects by the value of their key
Install
$ npm install @saxjst/sort-of
Usage
const sortOf = require('@saxjst/sort-of');
const people = [
{
name: "alice",
age: 15
},
{
name: "bob",
age: 9
},
{
name: "aaron",
age: 12
},
]
sortOf(people, ['age'], 'asc');
// [
// {
// name: "bob",
// age: 9
// },
// {
// name: "aaron",
// age: 12
// },
// {
// name: "alice",
// age: 15
// }
// ]
API
Number[]
| Object[]
sortOf(arr, [path], command) ⇒ Sort objects by the value of their key
Kind: global function
Returns: Number[]
| Object[]
- the sorted array
Param | Type | Default | Description |
---|---|---|---|
arr |
Number[] OR Object[]
|
the array to retrieve the value from. | |
[path] | String[] |
[] |
the key to sort by |
command | String |
asc or desc |
License
MIT © saxjst