> For AI agents: the complete documentation index is available at https://massaman.dev/llms.txt, the full documentation bundle is available at https://massaman.dev/llms-full.txt.

# orderBy (Functional Programming) es-toolkit

Creates a function that sorts objects by criteria and sort orders. Use it with [`pipe`](https://massaman.dev/reference/fp/pipe.md).

```typescript
const result = pipe(array, orderBy(criteria, orders));
```

::: info

Prefer the original es-toolkit [`orderBy`](https://massaman.dev/reference/array/orderBy.md) in ordinary code. Use this `fp` variant when composing transformations with [`pipe`](https://massaman.dev/reference/fp/pipe.md).

:::

## Usage

`orderBy` sorts the piped array by each criterion in order. Each order controls whether the matching criterion is sorted ascending or descending.

```typescript
import { orderBy, pipe } from 'es-toolkit/fp';

const users = [
  { name: 'a', age: 2 },
  { name: 'b', age: 1 },
];

pipe(users, orderBy(['age'], ['asc'])); // => [{ name: 'b', age: 1 }, { name: 'a', age: 2 }]
```

#### Parameters


criteriaArray<((item: T) => unknown) | keyof T>required

The object keys and/or selector functions used for comparison.


ordersArray<'asc' | 'desc'>required

The sort order for each criterion.

#### Returns

A function that maps a `readonly T[]` to a new, sorted array.

```typescript
(array: readonly T[]) => T[]
```


Source: es-toolkit

Re-exported verbatim from [`es-toolkit`](https://es-toolkit.dev/fp/reference/orderBy.html). Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.
