A RetroSearch Logo

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

Search Query:

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

Lodash _.max() Method - GeeksforGeeks

Lodash _.max() Method

Last Updated : 02 Sep, 2024

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: 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


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