javascript - Get the element in the array with the max value of a property using jQuery -


i have array of custom javascript object has property named order. have array of object, , want item highest "order".

since i'm relatively new jquery, , coming c# background 1 of instances highly appreciate linq :)

anyway, cut long story short, i've checked following links return value , not reference of array element itself... little in changing return element appreciated.

jquery min/max property array of elements

element max height set of elements

the custom object in question(which have array of) follows:

var severity = function (key, value, order) {     this.key = key;     this.value = value;     this.order = order; }; 

maybe got wrong... looking for?

function gethighest(array) {     var max = {};     (var = 0; < array.length; i++) {         if (array[i].order > (max.order || 0))             max = array[i];     }     return max; }  // var array = [object, object, object ...]; var highest = gethighest(array); 

demo: http://jsfiddle.net/c6gfj/


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -