Hooks
Functions
sortBy
sortBy function able to sort array of object order with array.sort compare function by key.
Example
import sortBy from '@/utils/sortBy'
const arr = [
{
name: 'Carolyn Perkins',
email: 'eileen_h@hotmail.com',
},
{
name: 'Terrance Moreno',
email: 'terrance_moreno@infotech.io',
},
{
name: 'Ron Vargas',
email: 'ronnie_vergas@infotech.io',
},
{
name: 'Luke Cook',
email: 'cookie_lukie@hotmail.com',
},
]
const data = arr.sort(sortBy('name', false , (a) => a.toUpperCase()))
// output: [
// {
// name: 'Carolyn Perkins',
// email: 'eileen_h@hotmail.com',
// },
// {
// name: 'Luke Cook',
// email: 'cookie_lukie@hotmail.com',
// },
// {
// name: 'Ron Vargas',
// email: 'ronnie_vergas@infotech.io',
// },
// {
// name: 'Terrance Moreno',
// email: 'terrance_moreno@infotech.io',
// },
// ]
Params
| param | Description | Type | Default |
|---|---|---|---|
| field | key of the object that target to sort | string | - |
| reverse | Order of the result, true for descending, false for ascending | boolean | - |
| primer | Callback closure for key | (key: string) => (key) => void | - |
Return
| return | Description | Type | Default |
|---|---|---|---|
| result | Sort result callback | (a, b) => boolean | - |