Answers for "js max array"

14

max value in array javascript

// For large data, it's better to use reduce. Supose arr has a large data in this case:
const arr = [1, 5, 3, 5, 2];
const max = arr.reduce((a, b) => { return Math.max(a, b) });

// For arrays with relatively few elements you can use apply: 
const max = Math.max.apply(null, arr);

// or spread operator:
const max = Math.max(...arr);
Posted by: Guest on November-27-2020
1

js max array

Math.min(...arr) // min
Math.max(...arr) // max
Posted by: Guest on August-24-2021
10

javascript get array min and max

//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
Posted by: Guest on July-31-2019
4

js max value of array

let numbers = [4, 13, 27, 0, -5]; // Get max value of an array in Javascript

Math.max.apply(null, numbers); // returns 27
Posted by: Guest on March-25-2020
1

javascript max array

var values = [3, 5, 6, 1, 4];

var max_value = Math.max(...values); //6
var min_value = Math.min(...values); //1
Posted by: Guest on August-06-2020
1

js max array

Math.max(...array);
Posted by: Guest on March-06-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language