A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/lodash-_-sum-method/ below:

Lodash _.sum() Method - GeeksforGeeks

Lodash _.sum() Method

Last Updated : 02 Sep, 2024

Lodash _.sum() method is used to find the sum of the values in the array. 

Syntax:
_.sum(array);
Parameter: 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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4