Dapatkan nomor terbesar dalam array javascript
const array1 = [1, 3, 2];
Math.max(...array1);
// expected output: 3
Jerky
const array1 = [1, 3, 2];
Math.max(...array1);
// expected output: 3
const result = (data) => {
let max = 0;
for (let i = 0; i < data.length; i++) {
if (data[i] > max) {
max = data[i];
}
}
console.log("===> :: max", max);
}
const inputData = [2, 3, 5, 4, 54, 69, 4, 44, 3, 6, 45, 6, 4, 6]
result(inputData);
//get min/max value of arrays
function getArrayMax(array){
return Math.max.apply(null, array);
}
function getArrayMin(array){
return Math.min.apply(null, array);
}
var ages=[11, 54, 32, 92];
var maxAge=getArrayMax(ages); //92
var minAge=getArrayMin(ages); //11
var arr = [1, 2, 3];
var max = arr.reduce(function(a, b) {
return Math.max(a, b);
});
var arr = [1, 2, 3];
var max = arr.reduce(function(a, b) {
return Math.max(a, b);
}, -Infinity);
function maxFromArray(array) {
return array.reduce(function(a, b) {
return Math.max(a, b);
}, -Infinity);
}