Friday, September 5, 2025
HomeLanguagesJavascriptLodash _.mean() Method

Lodash _.mean() Method

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.

The _.mean() method is used to find the mean of the values in the array.

Syntax:

_.mean( array )

Parameters: This method accepts a single parameter as mentioned above and described below:

  • array: It is the array that the method iterates over to get the mean of all the values.

Return Value: This method returns the mean of the values in the array.

Example 1:

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
    
// Use of _.mean()  
// method 
let mean_val = _.mean([15, 7, 38, 46, 82]); 
        
// Printing the output  
console.log(mean_val);


Output:

37.6

Example 2:  

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
    
// Use of _.mean()  
// method 
let mean_val = _.mean([2, 3, 4, 6, 7, 8]); 
        
// Printing the output  
console.log(mean_val);


Output:

5

Example 3:  

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
    
// Use of _.mean()  
// method 
let mean_val = _.mean([10, -4, -6, 8, 12]); 
        
// Printing the output  
console.log(mean_val);


Output:

4
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
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6638 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11866 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7027 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS