The Wayback Machine - https://web.archive.org/web/20240204105104/https://www.geeksforgeeks.org/lodash-_-minby-method/
Open In App
Related Articles

Lodash _.minBy() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Lodash _.minBy() method is used to compute the minimum value from the original array by iterating over each element in the array using the Iteratee function. It is almost the same as the _.min() function.

Syntax:

_.minBy(array, [iteratee = _.identity]);

Parameters:

  • array: It is the array that the method iterates over to get the minimum element.
  • iteratee: It is the function that is invoked for every element in the array.

Return Value:

This method returns the minimum element.

Example 1: In this example, we are printing the minimum value of the given array by the use of the _.minBy() method.

Javascript




// Requiring the lodash library 
const _ = require("lodash");
 
// Original array
let arr = [{ 'n': 4 }, { 'n': 2 }, { 'n': 6 }];
 
// Use of _.minBy() method
let min_val =
    _.minBy(arr, function (o) { return o.n; });
 
// Printing the output 
console.log(min_val);


Output:

{ 'n': 2 }

Example 2: In this example, we are printing the minimum value of the given array by the use of the _.minBy() method.

Javascript




// Requiring the lodash library 
const _ = require("lodash");
 
// Original array
let arr = [{ 'n': 10 }, { 'n': 5 },
{ 'n': 3 }, { 'n': 12 }];
 
// Use of _.minBy() method
let min_val = _.minBy(arr, 'n');
 
// Printing the output 
console.log(min_val);


Output:

{ 'n': 3 }

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks 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!

Looking for a place to share your ideas, learn, and connect? Our Community portal is just the spot! Come join us and see what all the buzz is about!


Last Updated : 25 Oct, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials