The only examples I have been able to find of people using $.each are html samples, and it’s not what I want. I have the following object:
var obj = {
obj1: 39,
obj2: 6,
obj3: 'text'
obj4: 'text'
obj5: 0
};
I loop through the object like so:
$(array).each(function(index, value) {
// ...
});
I want to sort by obj3 and obj4. Preferrably not using an asynchronous method, how can I sort the results before (or during) output? (I also don’t want to loop through this twice, as there could be hundreds at any given time.
is not an array (its name notwithstanding). It is an object. The idea of sorting by
obj3andobj4doesn’t really make sense.Now, if you were to convert this object to an array of objects, you could sort that array with the
array.sortmethod.and of course to sort by a numeric property, it’d simply be: