views:

26

answers:

1

I have a JSON object collection:

var Gallery = [
    { "Order": 1, "Page": 1, "LargeImage": "large.jpg", "ThumbImage": "thumb.jpg" }, 
    { "Order": 2, "Page": 1, "LargeImage": "large2.jpg", "ThumbImage": "thumb2.jpg" }];

I want to each over this object but after the collection is sorted on "Order". What is the best way to do this?

+2  A: 

To sort the Array, try this:

Gallery.sort(function(a,b) {
    return a.Order - b.Order;
});

But be sure to test the result in IE, as it can be a little funny with .sort().

Then use $.each() like normal to iterate over the Array.

patrick dw