Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

find min value in array javascript

// find mimimum value of array in javascript
// array reduce method
const arr = [49,2,71,5,38,96];
const min = arr.reduce((a, b) => Math.min(a, b));
console.log(min); // 2

// math.min apply method
const min_ = Math.min.apply(null, arr);
console.log(min_); // 2

// or math.min spread operator method
const min__ = Math.min(...arr);
console.log(min__); // 2
Comment

javascript index of min value in array

arr = [11, 10, 10];
var index = arr.indexOf(Math.max(...arr));
Comment

javascript minimum number in array

const min = arr => Math.min(...arr);
Comment

javascript find the min in array of numbers

// Assuming the array is all integers,
// Math.min works as long as you use the spread operator(...).

let arrayOfIntegers = [9, 4, 5, 6, 3];
let min = Math.min(...arrayOfIntegers);
// => 3 
Comment

js min number in array

var min = Math.min.apply(null, arr),
    max = Math.max.apply(null, arr);
Comment

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
})();
Comment

PREVIOUS NEXT
Code Example
Javascript :: js string contains 
Javascript :: node read file sync 
Javascript :: react-native android build apk 
Javascript :: react type div onClick 
Javascript :: jquery get data attribute 
Javascript :: how to hash with crypto Node.js 
Javascript :: javascript title string 
Javascript :: boilerplate node js server 
Javascript :: activeclassname in react router v6 
Javascript :: owl.js cdn 
Javascript :: javascript average of arguments 
Javascript :: how to stop browser back js history.pushState 
Javascript :: delete element 
Javascript :: react js console log not working 
Javascript :: mongoose connect to mongodb 
Javascript :: javascript change background color 
Javascript :: javascript check if string contains substring 
Javascript :: redux devtools extention in redux toolkit 
Javascript :: how to close tab by javascript 
Javascript :: async for loop 
Javascript :: react-native run-ios command 
Javascript :: how to find the index of an item in nodelist in js 
Javascript :: vue inline style bind 
Javascript :: javascript loop through child elements 
Javascript :: expo react native 
Javascript :: save form data jquery 
Javascript :: javascript websocket 
Javascript :: concat object 
Javascript :: truncate a string js 
Javascript :: javascript Using Math.min() on an Array 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =