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
1let numbers = [4, 13, 27, 0, -5]; // Get max value of an array in Javascript
2
3Math.max.apply(null, numbers); // returns 27
4
1function findHighestNumber(nums) {
2
3 let inputs = nums.filter((val, i) => nums.indexOf(val) === i)
4 let max = Math.max(...nums);
5 let min = Math.min(...nums);
6
7 return max + (-min);
8}
9
10console.log(difference([1, 7, 18, -1, -2, 9]));
1int[] a = new int[] { 20, 30, 50, 4, 71, 100};
2 int max = a[0];
3 for(int i = 1; i < a.length;i++)
4 {
5 if(a[i] > max)
6 {
7 max = a[i];
8 }
9 }
10
11 System.out.println("The Given Array Element is:");
12 for(int i = 0; i < a.length;i++)
13 {
14 System.out.println(a[i]);
15 }
16
17 System.out.println("From The Array Element Largest Number is:" + max);