Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

JavaScript Array Minimum Method

JavaScript has no built-in function for finding the lowest value in an array, so the most efficient approach is a custom method that iterates through the array, comparing values to identify the lowest.

Example (Find Min)

function myArrayMin(arr) {
  let len = arr.length;
  let min = Infinity;
  while (len–) {
    if (arr[len] < min) {
      min = arr[len];
    }
  }
  return min;
}

JavaScript Array Maximum Method

JavaScript lacks a built-in function to find the highest value in an array, so a custom method is used to iterate and compare values efficiently.

Example (Find Max)

function myArrayMax(arr) {
  let len = arr.length;
  let max = –Infinity;
  while (len–) {
    if (arr[len] > max) {
      max = arr[len];
    }
  }
  return max;
}