JavaScript || How To Get The Minimum & Maximum Values In A Simple & Object Array

Print Friendly, PDF & Email

The following is a module with functions which demonstrates how to get the minimum and maximum values in a simple and object array.

The functions on this page allows for an optional selector function as a parameter, which makes them general enough to work on arrays of any type.


1. Simple Array

The example below demonstrates the use of ‘Utils.arrayMin‘ and ‘Utils.arrayMax‘ to get the minimum and maximum values from a simple array.


2. Object Array

The example below demonstrates the use of ‘Utils.arrayMin‘ and ‘Utils.arrayMax‘ to get the minimum and maximum values from an object array.

In this example, a selector is used, which extracts the value to be used in the evaluation.


3. Mixed Array

The example below demonstrates the use of ‘Utils.arrayMin‘ and ‘Utils.arrayMax‘ to get the minimum and maximum values from a mixed array.

In this example, a selector is used, which extracts the value to be used in the evaluation.


4. Utils Namespace

The following is the Utils.js Namespace. Include this in your project to start using!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.

Leave a Reply