gomakethings.com

Sorting an array by multiple criteria with vanilla JavaScript

open original

Sorting an array by multiple criteria with vanilla JavaScript

Last week, my friend Andrew Borstein was playing around with a JavaScript upvoting system, and asked:
I want to sort an array based on two properties. First sort by an integer, next sort by a string. So an array of objects might look like this:
[ { title: 'Apple', votes: 1 }, { title: 'Milk', votes: 2 }, { title: 'Carrot', votes: 3 }, { title: 'Banana', votes: 2 } ] and then be sorted into thi

via gomakethings.com