Array.prototype.reduce() is good for stuff like this: to perform aggregate operations (like min, max, avg, etc.) on an array, and return a single result:

myArray.reduce(function(prev, curr) {
    return prev.Cost < curr.Cost ? prev : curr;
});

...or you can define that inner function with ES6 function syntax:

myArray.reduce((prev, curr) => prev.Cost < curr.Cost ? prev : curr);

If you want to be cute you can attach this to the Array prototype:

Array.prototype.hasMin = function(attrib) {
    return (this.length && this.reduce(function(prev, curr){ 
        return prev[attrib] < curr[attrib] ? prev : curr; 
    })) || null;
 }

Now you can just say:

myArray.hasMin('ID')  // result:  {"ID": 1, "Cost": 200}
myArray.hasMin('Cost')    // result: {"ID": 3, "Cost": 50}
myEmptyArray.hasMin('ID')   // result: null

Please note that if you intend to use this, it doesn't have full checks for every situation. If you pass in an array of primitive types, it will fail. If you check for a property that doesn't exist, or if not all the objects contain that property, you will get the last element. This version is a little more bulky, but has those checks:

Array.prototype.hasMin = function(attrib) {
    const checker = (o, i) => typeof(o) === 'object' && o[i]
    return (this.length && this.reduce(function(prev, curr){
        const prevOk = checker(prev, attrib);
        const currOk = checker(curr, attrib);
        if (!prevOk && !currOk) return {};
        if (!prevOk) return curr;
        if (!currOk) return prev;
        return prev[attrib] < curr[attrib] ? prev : curr; 
    })) || null;
 }
Answer from Tristan Reid on Stack Overflow
Top answer
1 of 16
297

Array.prototype.reduce() is good for stuff like this: to perform aggregate operations (like min, max, avg, etc.) on an array, and return a single result:

myArray.reduce(function(prev, curr) {
    return prev.Cost < curr.Cost ? prev : curr;
});

...or you can define that inner function with ES6 function syntax:

myArray.reduce((prev, curr) => prev.Cost < curr.Cost ? prev : curr);

If you want to be cute you can attach this to the Array prototype:

Array.prototype.hasMin = function(attrib) {
    return (this.length && this.reduce(function(prev, curr){ 
        return prev[attrib] < curr[attrib] ? prev : curr; 
    })) || null;
 }

Now you can just say:

myArray.hasMin('ID')  // result:  {"ID": 1, "Cost": 200}
myArray.hasMin('Cost')    // result: {"ID": 3, "Cost": 50}
myEmptyArray.hasMin('ID')   // result: null

Please note that if you intend to use this, it doesn't have full checks for every situation. If you pass in an array of primitive types, it will fail. If you check for a property that doesn't exist, or if not all the objects contain that property, you will get the last element. This version is a little more bulky, but has those checks:

Array.prototype.hasMin = function(attrib) {
    const checker = (o, i) => typeof(o) === 'object' && o[i]
    return (this.length && this.reduce(function(prev, curr){
        const prevOk = checker(prev, attrib);
        const currOk = checker(curr, attrib);
        if (!prevOk && !currOk) return {};
        if (!prevOk) return curr;
        if (!currOk) return prev;
        return prev[attrib] < curr[attrib] ? prev : curr; 
    })) || null;
 }
2 of 16
72

One way is to loop through all elements and compare it to the highest/lowest value.

(Creating an array, invoking array methods is overkill for this simple operation).

 // There's no real number bigger than plus Infinity
var lowest = Number.POSITIVE_INFINITY;
var highest = Number.NEGATIVE_INFINITY;
var tmp;
for (var i=myArray.length-1; i>=0; i--) {
    tmp = myArray[i].Cost;
    if (tmp < lowest) lowest = tmp;
    if (tmp > highest) highest = tmp;
}
console.log(highest, lowest);
🌐
Medium
rathoreaparna678.medium.com › how-to-get-min-or-max-value-of-a-property-in-a-javascript-array-of-objects-b39c279205b9
How to Get Min or Max Value of a Property in a JavaScript Array of Objects? | by Aparna Rathore | Medium
July 17, 2023 - To get the minimum or maximum value of a specific property in a JavaScript array of objects, you can use the `reduce()` function along with some additional logic. Here’s an example of how you can achieve this: To find the minimum value: ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › max-min-value-of-an-attribute-in-an-array-of-objects-in-javascript
Max/Min value of an attribute in an array of objects in JavaScript - GeeksforGeeks
July 11, 2025 - Example: This example gets the minimum value of the y property by using the array.reduce() method. It returns the whole object.
🌐
CodeBurst
codeburst.io › javascript-finding-minimum-and-maximum-values-in-an-array-of-objects-329c5c7e22a2
JavaScript: Finding Minimum and Maximum values in an Array of Objects | by Brandon Morelli | codeburst
August 21, 2017 - Now that we have a simple Array of numbers, we use Math.min() or Math.max() to return the min/max values from our new Y value array. The spread operator allows us to insert an array into the built in function.
🌐
Daily Dev Tips
daily-dev-tips.com › posts › javascript-find-min-max-from-array-of-objects
JavaScript find min/max from array of objects
July 17, 2022 - We are very explicit with the above examples by using the curly brackets and returning the object. However, seeing we only have one line, we can write it as the shorthand function like this. const highest = users.reduce((prev, cur) => (cur.age > prev.age ? cur : prev)); const lowest = users.reduce((prev, cur) => (cur.age < prev.age ? cur : prev)); Way shorter, right, but it takes some of the readability in one go. ... We will get shown the following error: TypeError: Reduce of empty array with no initial value.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › min
Math.min() - JavaScript | MDN
console.log(Math.min(2, 3, 1)); // Expected output: 1 console.log(Math.min(-2, -3, -1)); // Expected output: -3 const array = [2, 3, 1]; console.log(Math.min(...array)); // Expected output: 1 ... Zero or more numbers among which the lowest value will be selected and returned. The smallest of the given numbers. Returns NaN if any of the parameters is or is converted into NaN. Returns Infinity if no parameters are provided. Because min() is a static method of Math, you always use it as Math.min(), rather than as a method of a Math object you created (Math is not a constructor).
🌐
CoreUI
coreui.io › answers › how-to-find-the-minimum-value-in-an-array-in-javascript
How to find the minimum value in an array in JavaScript · CoreUI
September 21, 2025 - For objects, use: Math.min(...array.map(item => item.value)). ... Follow Łukasz Holeczek on GitHub Connect with Łukasz Holeczek on LinkedIn Follow Łukasz Holeczek on X (Twitter) Łukasz Holeczek, Founder of CoreUI, is a seasoned Fullstack ...
Find elsewhere
🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › array › min and max value of an array
Min and max value of a JavaScript array - 30 seconds of code
December 30, 2023 - For more complex cases, such as finding the min/max value in an array of objects, you will have to use Array.prototype.map().
🌐
EncodedNA
encodedna.com › javascript › how-to-find-minimum-value-of-an-array-object.htm
JavaScript - How to find the Minimum value of an array object
&ltscript> const oStock = [ { ... ... Similarly, you can find the maximum or the highest value by just using ">" (greater than) sign. The .reduce() method can be used in many ways in JavaScript....
🌐
EyeHunts
tutorial.eyehunts.com › home › javascript find min value in an array of objects | example code
JavaScript find min value in an array of objects | Example code - EyeHunts
May 16, 2021 - <script> var data = [ { "x": "3/10/2020", "y": 0.02352007 }, { "x": "8/12/2021", "y": 0.0254234 }, { "x": "1/16/2010", "y": 0.02433546 }, { "x": "8/19/2015", "y": 0.0313423457 }]; console.log(JSON.stringify(data)); function getYs(){ return data.map(d => d.y); } function getMinY(){ return Math.min(...getYs()); } function getMaxY(){ return Math.max(...getYs()); } var res = getMinY(); console.log("Minimum value of y = " + res); </script> Output: Result will be same because Array object values are same.
🌐
Quora
quora.com › How-can-you-find-the-highest-and-lowest-in-an-array-of-objects-JavaScript-Javascript-arrays-object-average-development
How to find the highest and lowest in an array of objects/JavaScript (Javascript, arrays, object, average, development) - Quora
To find the highest and lowest values in an array of objects in JavaScript, iterate the array while comparing a numeric property (e.g., score, price). Below are concise, idiomatic patterns with examples and trade-offs.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-min-element-in-an-array
JavaScript – Min Element in an Array - GeeksforGeeks
July 23, 2025 - The reduce() method processes each element of the array, comparing it with an accumulator (res) to track the smallest value. It’s functional and concise, with O(n) time complexity, and is great for functional programming enthusiasts.
🌐
SheCodes
shecodes.io › athena › 72426-how-to-find-the-minimum-and-maximum-values-in-a-javascript-array
[JavaScript] - How to find the minimum and maximum values in a JavaScript array?
Array min max Math.min() Math.max() Asked 8 days ago in JavaScript by Emilia · how do I use template literals to include a variable name in a string · template literals JavaScript variables strings backticks · Asked 13 days ago in JavaScript by Celeste · how to add a property to an array of objects ·
🌐
DEV Community
dev.to › dailydevtips1 › javascript-find-minmax-from-array-of-objects-142g
JavaScript find min/max from array of objects - DEV Community
July 17, 2022 - Let's see how we can achieve that. We'll use the reduce method to extract one item from the array. The cool thing about the reduce is that the initial value is optional, so that we can omit it for now.
🌐
Reddit
reddit.com › r/learnjavascript › how to get object inside array with lowest value
r/learnjavascript on Reddit: How to get object inside array with lowest value
January 27, 2022 -

Not sure if this sounds weird or if my approach is completely wrong.

I have an array with objects inside, and I want to check which object has the lowest value at a specific "name" (I hope that is the correct term).

myArray = [
    {This: "A", That: "B", Number: 2},
    {This: "C", That: "D", Number: 1},
    {This: "E", That: "F", Number: 3}
]

In this case I want to check which object in my array has the lowest number. So the result would be {This: "C", That: "D", Number: 1}

I need this to still know what other values are in this object. So I can't just compare the last bit of the object and just have 1 as an answer. I need the whole object.

🌐
Stack Overflow
stackoverflow.com › questions › 68822293 › returning-min-value-found-in-array-of-objects
javascript - Returning Min Value found in array of objects - Stack Overflow
const obj = { small: [{ price: 10 }, { price: 90 }], medium: [{ price: 33 }, { price: 8 }], large: [{ price: 34 }, { price: 44 }] } console.log(Math.min(...Object.values(obj).flat().map(({price}) => price))); Object.values() Array.prototype.flat() Array.prototype.map()
🌐
TutorialsPoint
tutorialspoint.com › how-to-find-the-min-max-element-of-an-array-in-javascript
How to find the min/max element of an Array in JavaScript?
The Math.max() method returns the maximum number of all the digits passed to it, while Math.min() returns the minimum value. But both of these methods will not work for the array as they are only used with distinct digits. So, to use these methods to find min/max elements in the array we need ...
🌐
Reddit
reddit.com › r/learnjavascript › how to get minimum date from array of object
r/learnjavascript on Reddit: How to get minimum date from array of object
October 25, 2021 -

Hello,

I would like to get the minimum date of this array of objects bellow:

let activities = [
  { title: 'Hiking', date: '2019-06-13' },
  { title: 'Shopping', date: '2019-06-10' },
  { title: 'Trekking', date: '2019-06-22' },
  { title: 'Trekking', date: null }
]

let sortedActivities = activities.sort((a, b) => new Date(a.date) - new Date(b.date))
console.log(sortedActivities[0])

The problem is when date activities.date is null it always returns null .

What's the best way to reject null value from this comparison ?

Thanks