Carlos André Couto Carlos André Couto - 1 year ago 49
Javascript Question

Convert to array the return of jQuery Each and show max value

I have a function and need what she return a array and show the max value present.



var myCell = new_2ELayout.cells("a").cell;

maxHeight = function(){
$(myCell).find(".dhxform_base").each(function() {
var formHeight = $(this).outerHeight();
console.log(formHeight);
});
}




Answer Source

How to get an array

var myCell = new_2ELayout.cells("a").cell;

var array  = $(myCell).find(".dhxform_base").map(function() {
    return $(this).outerHeight();
}).get();

How to get the max value in an array

var max = Math.max.apply(null, array);

So all together

var myCell = new_2ELayout.cells("a").cell;

var maxHeight = function(){
    var array = $(myCell).find(".dhxform_base").map(function() {
        return $(this).outerHeight();
    }).get();

    return Math.max.apply(null, array);
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download