1// For large data, it's better to use reduce. Supose arr has a large data in this case:
2const arr = [1, 5, 3, 5, 2];
3const max = arr.reduce((a, b) => { return Math.max(a, b) });
4
5// For arrays with relatively few elements you can use apply:
6const max = Math.max.apply(null, arr);
7
8// or spread operator:
9const max = Math.max(...arr);
10
1//Returns number with highest value.
2var x = Math.max(-5, 12, 27);
3console.log(x)//27
1var arr = [1, 2, 3];
2var max = arr.reduce(function(a, b) {
3 return Math.max(a, b);
4});
1//get min/max value of arrays
2function getArrayMax(array){
3 return Math.max.apply(null, array);
4}
5function getArrayMin(array){
6 return Math.min.apply(null, array);
7}
8var ages=[11, 54, 32, 92];
9var maxAge=getArrayMax(ages); //92
10var minAge=getArrayMin(ages); //11
1var arr = [1,2,3];
2var max = arr.reduce(function(a, b) {
3 return Math.max(a, b);
4});
5