Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Lodash _.max() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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

The _.max() method is used to find the maximum element from the array. If the array is empty then undefined is returned.

Syntax:

_.max( 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 maximum element.

Return Value: This method returns the maximum element from the array.

Example 1:

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
    
// Use of _.max() method 
let max_val = _.max([]); 
        
// Printing the output  
console.log(max_val);

Output:

undefined

Example 2:  

Javascript




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

Output:

82

Example 3:  

Javascript




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

Output:

38

My Personal Notes arrow_drop_up
Last Updated : 02 Sep, 2020
Like Article
Save Article
Similar Reads
Related Tutorials