Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js to find min value in an array

(function () {
  const arr = [23, 65, 3, 19, 42, 74, 56, -42, 8, 88];
  // const arr = [];

  function findMinValue(arr) {
    if (arr.length) {
      let min = Infinity;

      for (let num of arr) {
        min = num < min ? num : min;
      }

      return min;
    }
    return 0; // or anything what you need
  }

  console.log(findMinValue(arr)); // => -42
})();
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #js #find #min #array
ADD COMMENT
Topic
Name
8+2 =