sum (for BigInts) es-toolkit
Returns the sum of all elements in an array of BigInts.
This function is available exclusively from es-toolkit/bigint to avoid potential conflicts with similar functions for other numeric types.
Usage
sum(nums)
Use sum when you want to add up BigInts. It adds every element of the array together and returns the total.
An empty array returns 0n, so splitting an array and summing the parts always gives the same answer as summing the whole.
Unlike number, BigInt stays exact no matter how large the values get, which makes it a good fit for money in the smallest currency unit, token amounts, or database identifiers.
Parameters
The array of BigInts to sum.
Returns
Returns the sum of all BigInts in the array. Returns 0n for empty arrays.
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.