Lodash - sum method



Syntax

_.sum(array)

Computes the sum of the values in array.

Arguments

  • array (Array) − The array to iterate over.

Output

  • (number) − Returns the sum.

Example

var _ = require('lodash');
var values = [1, 2, 3, 4, 5];
var result = _.sum(values);

console.log(result);

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

15
lodash_math.htm
Advertisements