Answers for "how to find max value in js function"

20

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

How to get maximum value in Javascript

let x = Math.max(1,3,45,59,698);
console.log(x);  //output 698
Posted by: Guest on February-25-2021

Code answers related to "how to find max value in js function"

Code answers related to "Javascript"

Browse Popular Code Answers by Language