This package allows you to sort a multi dimensional array easily.
With npm:
$ npm i multi-sortor with yarn:
$ yarn add multi-sortThere are multiple ways to use this package, check the example bellow:
import MultiSort from 'multi-sort';
const arr = [
{ first_name: 'John', last_name: 'Doe' },
{ first_name: 'Anthony', last_name: 'Zipher' },
{ first_name: 'Anthony', last_name: 'Carlos' },
];With arguments providing the object key and the direction:
const sortedByFirstName = MultiSort(arr, 'first_name', 'ASC');With arguments providing an array of object keys and directions:
const sortedByFirstAndLast = MultiSort(
arr,
['first_name', 'last_name'],
['ASC', 'DESC']
);Or, With an Object where the key represents the object key on the array provided and the value represents
the direction:
const sortedByFirstAndLast = MultiSort(arr, {
first_name: 'ASC',
last_name: 'DESC',
});MultiSort is an open-sourced software licensed under the MIT license.