Customizing javascript Array.sort() method

|
In Javascript, Array sort could be parametrized. You could change the behaviour of the Array.sort method by passing the comparison function to it :
var myArray=new Array(2,1,6,4,18,-1);

// Descending sort
alert(myArray.sort(function(x,y) {return y-x}));

// Ascending sort
alert(myArray.sort(function(x,y) {return x-y}));


You can setUp your own sort function for you own objects and needs...

Javascript array sort with custom comparators, Javascript sorting, Custom comparison for the javascript Array.sort method, Array.sort() with custom sorter, Descending Array.sort() in Javascript, Ascending and descending sort in javascript