JavaScript get max value in Array of objects | Examples code

There are many ways to get the max value in an array of objects in JavaScript. Like we can use loop through all values and compare them to the maximum value or sort the array or use Math. max.

For an example Array looks like this:

Examples of JavaScript get max value in Array of objects

Example 1

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

Output:

JavaScript get max value in Array of objects

Example 2

Output: Object { max: 6000 }

Example 3: sort()

First sort the JS array with a custom sorting function:

Then take the first is “Minimum” and last is “Maximum”:

Do comment if you have another way to it or have any suggestions.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.