Q:

Loop through input fields with jQuery to find the highest value?

I have a number of input[type=text] fields on my page and I want to loop through all of them in order to find and return the highest value.
Is there a way to do this with jQuery?
Thanks for any help.

A:

Here is one solution:
var highest = -Infinity;
$("input[type='text']").each(function() {
    highest = Math.max(highest, parseFloat(this.value));
});
console.log(highest);

Here is another solution:
var highest = $("input[type='text']").map(function() {
    return parseFloat(this.value);
}).get().sort().pop();

console.log(highest);

A:

Use Math.max function:
var nums = [];
$("input[type=text]").each( function() { nums.push( $(this).val() ); });
var max = Math.max.apply(Math, nums);

