Find the largest number contained in a JavaScript array
To get the largest number in the array of numbers we can use the reduce() function to compare each number and return the largest.
Advertisements
var arrNum = [10, 5, 20, 15]; var max = arrNum.reduce(function(a,b){ return (a > b) ? a : b; }); console.log(max); //20