Wednesday, October 15, 2025
HomeLanguagesJavascriptLodash _.sum() Method

Lodash _.sum() Method

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




// Requiring the lodash library 
const _ = require("lodash");
 
// Use of _.sum () method
let gfg = _.sum([5, 10, 15, 20, 25]);
 
// Printing the output 
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




// Requiring the lodash library 
const _ = require("lodash");
 
// Use of _.sum () method
let gfg = _.sum([8, -12, -13, 30, 45]);
 
// Printing the output 
console.log(gfg);


Output:

58
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
Previous article
Next article
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11952 POSTS0 COMMENTS
Shaida Kate Naidoo
6851 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS