Sponsor
Win a 1-year subscription to egghead.io (Worth $199)
Upgrade your programming skills.Egghead.io delivers a constant stream of short, bite-sized instructional lessons on the latest web development technologies.
Tip
If you have an array of objects like:
1 |
[{name:'joe'},{name:'emily'},{name:'david'},{name:'daniel'},{name:'mike'}] |
You can sort it with a computed property like this:
1 2 |
sortBy: ['name'], sortedNames: Ember.computed.sort('names','sortBy'), |
The cool thing about this is that the sorted array is automatically in-sync with the original array, so as you add and remove objects the array stays sorted.
See it in action over here and see how to sort it in descending order.
Bonus
Notice the sortBy property above is an array, this means you can sort by multiple properties e.g.
1 |
sortBy: ['name', 'age:desc'] |
That’s it for today!
Let me know what you think of today’s tip. Thanks.