Sort objects by the value of their key
$ npm install @saxjst/sort-of
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
// }
// ]
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 |
MIT © saxjst