본문 바로가기

jQuery

jQuery min/max in Array

var array = [5, 7, 89, 3, 0, 67];
var max = Math.max.apply(null, [5, 7, 89, 3, 0, 67]); // => 89

Or enhance the Array object itself:

Array.prototype.max = function() {
    return Math.max.apply(null, this);
};
Array.prototype.min = function() {
    return Math.min.apply(null, this);
};

Usage:

[5, 7, 89, 3, 0, 67].max(); //  => 89

출처 : http://www.mail-archive.com/jquery-en@googlegroups.com/msg14247.html