For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/bigint/minBy.md.

minBy (for BigInts) es-toolkit

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

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

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.

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.

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.

T

Throws

Throws a RangeError if the array is empty.

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.