Computes the sum of the numeric values produced for each element.
The source iterable.
The sum of the projected values.
Thrown when source is empty.
source is enumerated exactly once. Supply selector when elements are not already numeric.
const numbers = [1, 2, 3, 4, 5];const total = sum(numbers);console.log(total); // 15const people = [ { name: 'Alice', age: 25 }, { name: 'Bob', age: 30 },];const totalAge = sum(people, p => p.age);console.log(totalAge); // 55 Copy
const numbers = [1, 2, 3, 4, 5];const total = sum(numbers);console.log(total); // 15const people = [ { name: 'Alice', age: 25 }, { name: 'Bob', age: 30 },];const totalAge = sum(people, p => p.age);console.log(totalAge); // 55
Type of elements within the source iterable.
source
Optional projection that extracts the numeric value. Defaults to interpreting the element itself as a number.
Computes the sum of the numeric values produced for each element.