sum
Calculates the sum of an array of numbers.
null and undefined are treated as empty arrays and return 0.
Available since v2.0.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
array | readonly number[] | null | undefined | The array of numbers to sum |
Returns
Section titled “Returns”number — The sum of all values, or 0 for an empty array, null, or undefined
Examples
Section titled “Examples”Sum numbers
Section titled “Sum numbers”Calculates the sum of an array of numbers.
Sum with negative numbers
Section titled “Sum with negative numbers”Handles negative numbers correctly.
