#12 Sort Arrays

Sponsor

Win a 1-year subscription to egghead.io (Worth $199)
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:

You can sort it with a computed property like this:

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.

That’s it for today!

Let me know what you think of today’s tip.  Thanks.

Published by

Emad Ibrahim

Author of asp .net MVC & TDD, entrepreneur, passionate technologist, programmer and productivity nut. more at http://t.co/oSJXPvzu