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

Resig to the rescue:

Array.max = function( array ){
    return Math.max.apply( Math, array );
};

Warning: since the maximum number of arguments is as low as 65535 on some VMs, use a for loop if you’re not certain the array is that small.

Leave a Comment