JavaScript get max value in Array of objects | Example code

Use inbuilt method Math apply(), map(), reduce() to get the max value in Array of objects in JavaScript. The Array object lets you store multiple values in a single variable.

Ways to get max value in Array of objects:-

  • Using apply() and map() method
  • array.reduce() method
  • Using map(), Math, and the spread operator

JavaScript get max value in an array of objects Example code

Let’s see HTML example code with different ways:-

Using apply() and map() method

Program of gets the maximum value of y property by using apply() and map() method.

Using reduce()

Example code of how to gets the maximum value of y property by using reduce() method. It returns the whole object.

Using map(), Math, and the spread operator

Created a function to get max and min from Array.

Output: Result will same for all code because given Array values is same.

JavaScript get max value in Array of objects

Do comment if you have any doubts and suggestions on this JS Array topic.

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.