Answers for "js function to find maximum number in an array"

30

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 get max value in an array

const myArray = [1, 14, 32, 7];

const maxValue = Math.max(...myArray);

console.log(maxValue); // 32
Posted by: Guest on February-01-2022

Code answers related to "js function to find maximum number in an array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language