DEV Community

Cover image for Answer: How might I find the largest number contained in a JavaScript array?
Jeffrey Bodin
Jeffrey Bodin

Posted on

Answer: How might I find the largest number contained in a JavaScript array?

Use:

var arr = [1, 2, 3, 4];

var largest = arr.reduce(function(x,y) {
    return (x > y) ? x : y;
});

console.log(largest);

Alt Text

Top comments (0)