Open In App

Lodash _.mean() Method

Last Updated : 13 Nov, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Lodash_.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: In this example, the code requires the Lodash library and calculates the mean (average) value of a numeric array using the _.mean method, then displays the result in the console.

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: In this example, the code utilizes the Lodash library’s _.mean method to calculate the mean (average) value of a numeric array and displays the result in the console.

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: In this example, the code requires the Lodash library and calculates the mean (average) value of a numeric array, then displays the result in the console.

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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads