@justbe-utilities/array-sort
v1.3.4
Published
array sort utility
Downloads
16
Readme
Array Sort
Basic array sort using underscore.js, require underscore
Dependencies (no need to install mannually)
This package depends upon [email protected]
npm i [email protected] --save
install types @types/[email protected] if you are using typescript
npm i @types/[email protected] --save-dev
Installation
Use the node package manager npm to install @justbe-utilities/array-sort.
npm install @justbe-utilities/array-sort --save
Usage
...
import { ArraySortClass } from '@justbe-utilities/array-sort'
...
constructor(){
let sortedArray = ArraySortClass.sort(this.recentLocations, 'cO', 'desc');
//argument1 => array to be sorted
//argument2 => key on which you want to sort
//argument3 => order in which you want to sort array
//supported orders => 'desc' | 'asc'
//by default => 'asc'
}
Example
...
let array = [
{cO:1},
{cO:5},
{cO:3},
{cO:6},
];
let sortedArray = ArraySortClass.sort(array, 'cO', 'desc');
console.log(sortedArray);
// output
// {cO:6},
// {cO:5},
// {cO:3},
// {cO:1},
let sortedArray = ArraySortClass.sort(array, 'cO', 'asc');
console.log(sortedArray);
// output
// {cO:1},
// {cO:3},
// {cO:5},
// {cO:6},
...