@saxjst/sort-of
v1.0.1
Published
Sort objects by the value of their key
Downloads
2
Readme
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
sortOf(arr, [path], command) ⇒ Number[]
| Object[]
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