Sorting a Collection

A brief overview of how to use a comparator to sort our collections in Marionette.

Displaying contacts in alphabetical order

You’re probably slightly annoyed that our contacts aren’t displayed in alphabetical order.

If you’re obsessed with sorting, you might have fixed that already by changing the order in which the models are created in the collection. However, I’m sure you’ll agree that’s hardly a robust solution. Instead, let’s have the collection do the hard work for us.

We have the following names that we need to sort by firstName:

Get hands-on with 1200+ tech skills courses.