17
Find the maximum element from the array in javascript
In this article i am going to find the maximum value from the array,i will use multiple approach to find the maximum value from the array.
let max_value = [4,10,3,20];
Math.max.apply(0,max_value)// 20
let max_value = [4,10,3,20];
let sortedArray = max_value.sort((a,b)=>b-a);
sortedArray[0]; // 20
let max_value = [4,10,3,20];
Math.max(...max_value); // 20
let max_value = [4,10,3,20];
let max = max_value[0];
let i;
let len = max_value.length;
for(i=0;imax){
max = max_value[i]; // 20
}
}
let max_value = [4,10,3,20];
max_value.reduce((a,b)=>Math.max(a,b)); // 20
Please visit for more information codewithabu
17