InterviewHubPRO
Section Overview
Q250

Question 250 of 521

Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

48%
JavaScript Internals (521 Qs)•Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

How do you find the min and max values in an array

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
  var marks = [50, 20, 70, 60, 45, 30];
  function findMin(arr) {
    return Math.min.apply(null, arr);
  }
  function findMax(arr) {
    return Math.max.apply(null, arr);
  }

  console.log(findMin(marks));
  console.log(findMax(marks));