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?
asked Sep 9, 2010 at 0:56
Brian David Berman
7,72226 gold badges83 silver badges146 bronze badges
1 Answer 1
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.
answered Sep 9, 2010 at 1:12
user113716
323k64 gold badges454 silver badges441 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js