Friday, January 16, 2026
HomeLanguagesJavascriptLodash _.max() Method

Lodash _.max() Method

Lodash _.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:

  • 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: In this example, we are trying to find out the max element in an empty array and it is returning undefined.

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: In this example, we are trying to find out the max element in an array by the use of the _.max() method.

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: In this example, we are trying to find out the max element in an array by the use of the _.max() method.

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
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!
RELATED ARTICLES

Most Popular

Dominic
32474 POSTS0 COMMENTS
Milvus
117 POSTS0 COMMENTS
Nango Kala
6846 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12062 POSTS0 COMMENTS
Shaida Kate Naidoo
6985 POSTS0 COMMENTS
Ted Musemwa
7219 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6911 POSTS0 COMMENTS