// 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
arr = [11, 10, 10];
var index = arr.indexOf(Math.max(...arr));
const min = arr => Math.min(...arr);
// 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
var min = Math.min.apply(null, arr),
max = Math.max.apply(null, arr);
(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
})();