0
Q:

javascript max array

// 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);
2
Math.max(...array);
1
let numbers = [4, 13, 27, 0, -5]; // Get max value of an array in Javascript

Math.max.apply(null, numbers); // returns 27
2
var values = [3, 5, 6, 1, 4];

var max_value = Math.max(...values); //6
var min_value = Math.min(...values); //1
0
MAX_SAFE_INTEGER = 9007199254740991
0

New to Communities?

Join the community