Improved version of Cerbrus’ code:
var ordering = {}, // map for efficient lookup of sortIndex
sortOrder = ['fruit','candy','vegetable'];
for (var i=0; i<sortOrder.length; i++)
ordering[sortOrder[i]] = i;
somethingToSort.sort( function(a, b) {
return (ordering[a.type] - ordering[b.type]) || a.name.localeCompare(b.name);
});