Possible Duplicate:
How does Javascript's sort() work?
var myarray=[25, 8, 7, 41]
myarray.sort(function(a,b){return b - a})// for descending order
In a callback function, what does a and b variables refer to??
why and how does b-a exactly make array in descending order??
aandbare two of the values in the array, that you compare so Javascript can sort them.The function is called lots of times to determine where each element in the array is compared to all the others. The exact number of times the function is called depends on the number of elements in the array and their original order.
You need to return 0 if the two elements are equal, a negative number if
ashould be beforeband a positive number ifbshould be beforea.