JavaScript map min value | Example code

To get min from map in JavaScript use sort method. Array values will be changed.

JavaScript map min value Example

HTML example code:

First sorting an Array by value and then get zero index value. It will be a min map value.

<!DOCTYPE HTML> 
<html> 

<body> 

	<script> 

		var myArray = [
		{"ID": 1, "Cost": 200},
		{"ID": 2, "Cost": 1000},
		{"ID": 3, "Cost": 50},
		{"ID": 4, "Cost": 500}
		];

		myArray.sort(function (a, b) {
			return a.Cost - b.Cost
		})

		var min = myArray[0];

		console.log(min);

	</script> 
</body> 
</html>	

Output:

JavaScript map min value

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

Note: The 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.