orderBy es-toolkit
Returns a new array sorted by multiple criteria and sort directions.
Usage
orderBy(arr, criteria, orders)
Use orderBy when you want to perform compound sorting on an array of objects with multiple conditions. You can specify ascending or descending order for each criterion, and if values are the same for the first criterion, it sorts by the next criterion.
If the number of sort directions is less than the number of criteria, the last direction is repeated.
Parameters
The array of objects to sort.
The criteria to sort by. You can use property names of objects or functions that return values.
An array of sort directions for each criterion. 'asc' means ascending order, 'desc' means descending order.
Returns
A new array sorted by the specified criteria and directions.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.