Home > Community Toolbox Reference > Array utilities > Number array statistics
Returns the sum of numbers in the array or its subsection. If the array/subsection is empty, 0 is returned.
Argument | Type | Usage | Description |
---|---|---|---|
array | Array<Real> |
Required | The array to get the sum of. |
offset | Real |
Default: 0 |
The starting index of the subsection (for a negative offset, it will count from array end). |
length | Real |
Default: undefined |
The length of the subsection (for a negative length, it will count backwards from the offset position). |
Real
The following code finds the total gold shared between heroes in the party:
var _heroes = [
{ name: "Alice", level: 14, gold: 165 },
{ name: "Bob", level: 16, gold: 546 },
{ name: "Charlie", level: 9, gold: 1753 },
];
var _heroes_gold = array_map(_heroes, function(_hero) { return _hero.gold; });
var _total_gold = array_sum(_heroes_gold);
show_debug_message(_total_gold);
- 23.4.0 - Created a function to calculate the sum of the numbers array values.