Skip to content

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.

var arrNum = [10, 5, 20, 15];
var max = arrNum.reduce(function(a,b){
	return (a > b) ? a : b;
console.log(max); //20
See also  Check for balanced parentheses in an expression using Java

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.