Open In App

Lodash _.min() Method

Last Updated : 30 Oct, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Lodash _.min() method is used to find the minimum element from the array. If the array is empty then undefined is returned.

Syntax:

_.min(array);

Parameters:

  • array: It is the array that the method iterates over to get the minimum element.

Return Value:

This method returns the minimum element from the array.

Example 1: In this example, we are getting the undefined value as the given array is empty so the lodash _min() method returns the undefined value.

Javascript




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


Output:

undefined

Example 2: In this example, we are getting the minimum value of the given array by the use of the lodash _min() method.

Javascript




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


Output:

7

Example 3: In this example, we are getting the minimum value of the given array by the use of the lodash _min() method.

Javascript




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


Output:

-82


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

Similar Reads