You need a way to translate a string to a position in an array, i.e. index functions for an array.
There is one in new browsers, but for backward compatibility you need to add it if it is not there:
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(str) {
var i;
for (i = 0; i < this.length; i++) if (this[i] == str) return i;
return -1;
}
}
Now you can sort the array by turning the string into an index:
objects.sort(function(x,y){ return order.indexOf(x.id) - order.indexOf(y.id); });
: http://jsfiddle.net/Guffa/u3CQW/