The array of objects to be sorted.
The keys to sort the objects. Prefix a key with a hyphen (-) to sort in descending order.
The sorted array of objects.
const object = [
{ name: 'John', date: '2021-01-01' },
{ name: 'Alice', date: '2021-02-01' },
{ name: 'Bob', date: '2021-01-15' }
];
const sortedArray = sortObjectByMultipleKeys(object, ['name', '-date']);
console.log(sortedArray);
// Output: [
// { name: 'Alice', date: '2021-02-01' },
// { name: 'Bob', date: '2021-01-15' },
// { name: 'John', date: '2021-01-01' }
// ]
Generated using TypeDoc
Sorts an array of objects based on multiple keys.