Advertisement
728x90
You can use Math.min and Math.max methods on array variables to find the minimum and maximum elements within an array. Let's create two functions to find the min and max value with in an array,
javascript
1var marks = [50, 20, 70, 60, 45, 30];
2
3function findMin(arr) {
4 return Math.min.apply(null, arr);
5}
6
7function findMax(arr) {
8 return Math.max.apply(null, arr);
9}
10
11console.log(findMin(marks));
12
13console.log(findMax(marks));Advertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 75
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
246of476