Lodash _.sum() method is used to find the sum of the values in the array.
Syntax:
_.sum(array);
Parameter:
- array: This parameter holds the array to iterate over.
Return Value:
This method returns the sum of the values in the array.
Example 1: In this example, we are printing the sum of the numbers in an array by the use of the _.sum() method.
Javascript
const _ = require( "lodash" );
let gfg = _.sum([5, 10, 15, 20, 25]);
console.log(gfg);
|
Output:
75
Example 2: In this example, we are printing the sum of the numbers in an array by the use of the _.sum() method.
Javascript
const _ = require( "lodash" );
let gfg = _.sum([8, -12, -13, 30, 45]);
console.log(gfg);
|
Output:
58
Last Updated :
20 Oct, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...