Skip to content

sum

The sum() method adds all the numeric values of an immutable array and returns the total sum as a number.

Interactive example

Syntax

typescript
function sum<
	GenericInput extends readonly number[]
>(
	input: GenericInput
): number

Parameters

  • input: Array of numbers to add.

Return value

The total sum of all the elements of the array. When the input is a tuple, TypeScript can infer a literal sum if the compiler is able to compute it.

See also

  • reduce - To implement custom aggregations
  • group - To group and then summarize values

Sources

Released under the MIT license.