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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.