Example 1: javascript min max array
Math.max(1, 2, 3) // 3
Math.min(1, 2, 3) // 1
var nums = [1, 2, 3]
Math.min(...nums) // 1
Math.max(...nums) // 3
Example 2: 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);
Example 3: Find the maximum number of an array js
var arr = [1, 2, 3];
var max = arr.reduce(function(a, b) {
return Math.max(a, b);
});
Example 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
Example 5: javascript max array
var values = [3, 5, 6, 1, 4];
var max_value = Math.max(...values); //6
var min_value = Math.min(...values); //1
Example 6: how to find max in array
int[] a = new int[] { 20, 30, 50, 4, 71, 100};
int max = a[0];
for(int i = 1; i < a.length;i++)
{
if(a[i] > max)
{
max = a[i];
}
}
System.out.println("The Given Array Element is:");
for(int i = 0; i < a.length;i++)
{
System.out.println(a[i]);
}
System.out.println("From The Array Element Largest Number is:" + max);