This example is for sorting arrays by numbers (and dates) or strings.
Array.prototype.deepsort= function(){
var i, order= arguments, L= order.length, tem;
return this.sort(function(a, b){
i= 0;
while(i < L){
tem= order[i++];
var ao= a[tem] || 0, bo= b[tem] || 0;
if(ao== bo) continue;
return ao> bo? 1: -1;
}
return 0;
});
}
var a= [ [ 'z', 1, 0 ], [ 'a', 0, 1 ],['m',-1,10] ,['a','1',-1]];
alert(a.deepsort(0,1,2)+'\n\n'+a.deepsort(2,0,1))
Sorts on the selected index (passed as an argument).
If the items at that index in each array match,
sorts on the next index passed as an argument, if any.
Continue as long as the items match and there are more arguments.
You don't need to specify more than one index to sort by
a.deepsort(0);
a.deepsort(2);