Javascript Array max(prop)

Description

Javascript Array max(prop)


Array.prototype.max = function (prop) {
    var max = prop ? this[0][prop] : this[0];
    var len = this.length;
    for (var i = 1; i < len; i++) {
        var item = prop ? this[i][prop] : this[i];
        if (item > max) {
            max = item;//from  w ww .  j  a  v a 2s. co m
        }
    }
    return max;
};



PreviousNext

Related