> 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.

# minBy (for `BigInt`
s) es-toolkit

Returns the element of an array whose derived `BigInt` value is the smallest.

```typescript
const smallest = minBy(items, getValue);
```

::: info

This function is available exclusively from `es-toolkit/bigint` to avoid potential conflicts with similar functions for other numeric types.

:::

## Usage

### `minBy(items, getValue)`

Use `minBy` when the `BigInt`s you want to compare are inside objects and you want the whole object back, not just the number. Pass a function that pulls the value out of each element.

```typescript
import { minBy } from 'es-toolkit/bigint';

const accounts = [
  { owner: 'alice', balance: 10n },
  { owner: 'bob', balance: 30n },
  { owner: 'carol', balance: 20n },
];

const poorest = minBy(accounts, account => account.balance);
console.log(poorest); // { owner: 'alice', balance: 10n }
```

When several elements tie for the smallest value, the first one wins. `getValue` also receives the index and the whole array.

```typescript
import { minBy } from 'es-toolkit/bigint';

const first = { id: 'a', score: 10n };
const second = { id: 'b', score: 10n };
console.log(minBy([first, second], item => item.score)); // { id: 'a', score: 10n }
```

An empty array has no element to return, so it throws.

```typescript
import { minBy } from 'es-toolkit/bigint';

minBy([], () => 0n); // RangeError: Cannot find the minimum of an empty array.
```

#### Parameters


itemsreadonly T[]required

The array of elements to search.


getValue(element: T, index: number, array: readonly T[]) => bigintrequired

A function that returns the `BigInt` to compare by.

#### Returns

Returns the element with the smallest derived `BigInt`. Returns the first of several elements that tie.

```typescript
T
```

#### Throws

Throws a `RangeError` if the array is empty.


Source: es-toolkit

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