To find the maximum y value of the objects in array:

Math.max.apply(Math, array.map(function(o) { return o.y; }))

or in more modern JavaScript:

Math.max(...array.map(o => o.y))

Warning:

This method is not advisable, it is better to use reduce. With a large array, Math.max will be called with a large number of arguments, which can cause stack overflow.

Answer from tobyodavies on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › max
Math.max() - JavaScript | MDN
console.log(Math.max(1, 3, 2)); // Expected output: 3 console.log(Math.max(-1, -3, -2)); // Expected output: -1 const array = [1, 3, 2]; console.log(Math.max(...array)); // Expected output: 3 ... Zero or more numbers among which the largest value will be selected and returned. The largest 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 max() is a static method of Math, you always use it as Math.max(), rather than as a method of a Math object you created (Math is not a constructor).
Discussions

ES6 Find the maximum number of an array of objects?

If you want to use ES6 and get this done in one line:

const shots = [
{id: 1, amount: 2},
{id: 2, amount: 4},
{id: 3, amount: 52},
{id: 4, amount: 36},
{id: 5, amount: 13},
{id: 6, amount: 33}
];

shots.reduce((acc, shot) => acc = acc > shot.amount ? acc : shot.amount, 0);

Can replace the ternary with a Math.max(acc, shot.amount), along with many other multiple methods. The issue with the reduce function you produced on SO, your reducer accumulator/initial value (0) was placed in the wrong spot.

More on reddit.com
🌐 r/javascript
3
0
December 12, 2014
How can I easily obtain the min or max element of a JavaScript array? - TestMu AI Community
How can I easily obtain the min or max element of a JavaScript array · You can easily obtain the minimum and maximum elements of a JavaScript array using the Math.min() and Math.max() functions along with the spread operator. Here’s how you can do it: More on community.testmu.ai
🌐 community.testmu.ai
0
August 15, 2024
Map or Reduce to calculate max value from JSON
That SO solution is more elegant. It uses map to create a new array of just the values, then passes that to the built-in Math.max. Your solution is slightly more complicated and basically does just what Math.max does anyway. Edit: However, I knocked together a quick jsperf and it looks like the Math.max version is slower: http://jsperf.com/math-max-vs-ternery Personally I'd still go with Math.max as I find it easier to understand, and I really doubt there will be many situations in which this'd be a performance bottleneck. More on reddit.com
🌐 r/javascript
12
2
May 26, 2015
javascript - How to do reduce math.max to an array of objects - Stack Overflow
But the previous code example shows ... not "to get the object with the maximum number value" ... ¯\_(ツ)_/¯ 2018-12-20T04:42:46.503Z+00:00 ... You had the right idea. Here's a solution that uses reduce and keeps tabs on the highest-ranking object in the array:... More on stackoverflow.com
🌐 stackoverflow.com
🌐
danvega.dev
danvega.dev › blog › find-max-array-objects-javascript
How to find the max id in an array of objects in JavaScript
March 14, 2019 - This means that you can use the map function to get an array of id's and then pass it into the max() function using the spread operator. assert(Math.max(...characters.map(user => user.id)) === 444); Spread syntax allows an iterable such as an ...
🌐
Seanconnolly
seanconnolly.dev › javascript-find-element-with-max-value
How to get the element with the max value in a JavaScript array · Sean Connolly
Let's apply Array.reduce to our use case to find the max value element in our array. const playerWithMostWins = players.reduce( (prev, current) => { return prev.wins > current.wins ? prev : current } ); And if you need to change the logic to the player with the least wins (for the wall of shame?), it's the same function but just with a different comparison function:
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-get-index-of-the-max-value-in-array-of-objects
How to Get Index of the Max Value in Array of Objects ? - GeeksforGeeks
August 5, 2025 - It executes a provided function for each value of the array and accumulates a single result. ... Example: The below code explains the use of the reduce() method to get the index of the max value in an array of objects...
🌐
CoreUI
coreui.io › answers › how-to-find-the-maximum-value-in-an-array-in-javascript
How to find the maximum value in an array in JavaScript · CoreUI
September 21, 2025 - For objects, use: Math.max(...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 ...
🌐
Built In
builtin.com › articles › javascript-array-max
3 Methods to Find the JavaScript Array Max | Built In
Arrays are a versatile structure in JavaScript that holds multiple data types. Find the maximum value in an array using for loop, math.max() and the reduce method.
Find elsewhere
🌐
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.
🌐
Reddit
reddit.com › r › javascript › comments › 7xhjg9 › es6_find_the_maximum_number_of_an_array_of_objects
r/javascript - ES6 Find the maximum number of an array of objects?
December 12, 2014 - shots.reduce((max, shot) => max && max.amount > shot.amount ? max : shot, null); This also handles empty shots lists returning null rather than an initial value that appears to be a valid amount object (as would be the case in the accepted answer).
🌐
Jason Watmore's Blog
jasonwatmore.com › post › 2021 › 09 › 14 › vanilla-js-get-the-max-prop-value-from-an-object-array-in-javascript
Vanilla JS - Get the max prop value from an object array in JavaScript | Jason Watmore's Blog
September 14, 2021 - Run the example vanilla JS on StackBlitz at https://stackblitz.com/edit/vanilla-js-get-max-prop-value-from-object-array. For more info on the Vanilla JS functions and operator used in the example see the below links: Array map function - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-search-the-max-value-of-an-attribute-in-an-array-object
How To Search The Max Value of an Attribute in an Array Object? - GeeksforGeeks
July 15, 2025 - a[0].value: After sorting, the first object (a[0]) will have the highest value, so it's assigned to max. The forEach approach iterates through the array of objects, checking each object's attribute value. It keeps track of the highest value found.
🌐
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 - const maxScore = findMaxValue(data, ‘score’); console.log(maxScore); // Output: 95 ``` In both cases, the `reduce()` function is used to iterate over each object in the array. The initial value (`Infinity` for minimum, `-Infinity` for maximum) is set to ensure that the first comparison sets the initial minimum or maximum value correctly.
🌐
W3Schools
w3schools.com › jsref › jsref_max.asp
JavaScript Math max() Method
❮ Previous JavaScript Math Object ... let d = Math.max(-5, -10); let e = Math.max(1.5, 2.5); Try it Yourself » · The Math.max() method returns the number with the highest value....
🌐
TutorialsPoint
tutorialspoint.com › how-to-search-the-max-value-of-an-attribute-in-an-array-object
How to search the max value of an attribute in an array object ?
July 18, 2023 - When working with objects, we often need to search for the max value of an attribute in an array of objects. We can use various javascript inbuilt functions like reduce() method, and map() method and we can also use a simple for loop to search for the max value.
🌐
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 - If n is greater than or equal to the length of the array, we'll get the original array back. const minN = (arr, n = 1) => [...arr].sort((a, b) => a - b).slice(0, n); const maxN = (arr, n = 1) => [...arr].sort((a, b) => b - a).slice(0, n); minN([1, 2, 3]); // [1] minN([1, 2, 3], 2); // [1, 2] maxN([1, 2, 3]); // [3] maxN([1, 2, 3], 2); // [3, 2] For more complex cases, such as finding the min/max value in an array of objects, you will have to use Array.prototype.map().
🌐
TestMu AI Community
community.testmu.ai › ask a question
How can I easily obtain the min or max element of a JavaScript array? - TestMu AI Community
August 15, 2024 - How can I easily obtain the min or max element of a JavaScript array · You can easily obtain the minimum and maximum elements of a JavaScript array using the Math.min() and Math.max() functions along with the spread operator.
🌐
Reddit
reddit.com › r/javascript › map or reduce to calculate max value from json
r/javascript on Reddit: Map or Reduce to calculate max value from JSON
May 26, 2015 -

Hi Reddit,

I have question about a very simple problem, I'm not looking for lines of code, but more for an explanation about way programmers seem to think in a certain way.

I'm not new to programming, but I'm new to javascript so I sometimes wonder if I can do thing better.

My problem: I have a simple JSON object and I want to calculate the max value for a certain field (val).

var data = {
        2013: [
            {
                prov: "salerno",
                val: 100
            },
            {
                prov: "napoli",
                val: 35
            },
            {
                prov: "avellino",
                val: 0
            }
        ]
    };

array = data[2013];

My initial thought was I have a bunch of values and I want only one (the max) so I will use a reduce function. So I wrote this:

array.reduce(function(max, x) { return (x.val > max) ? x.val : max; }, 0)

I was pretty happy with my code, then I checked on stackoverflow to see if there is a better way to do it and I found this:

Finding the max value of an attribute in an array of objects

The right answer with a lot of upvotes was:

Math.max.apply(Math,array.map(function(o){return o.y;}))

While I understand the code and how it works (get an array from the JSON and apply the Math.max()), I'm not sure way all the people in StackOverflow went for a solution with map() (to extract the array) instead to go for a solution with reduce() (to have a single value).

Can anyone help me to understand better?

🌐
QuickRef.ME
quickref.me › home › how to find the index of the maximum item of an array in javascript - quickref.me
How to find the index of the maximum item of an array in JavaScript - QuickRef.ME
In this Article we will go through how to find the index of the maximum item of an array only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.