Hi Iam learning Javascript sort method but not able to understand from different sources.
if any one have few minutes then please explain how it works-
i mean how execution goes , which values are compare first and so on,
Please do not paste links I have visited it.
Hi,
`arr=[3,1,5,4,2];
arr.sort(function(a,b){
return a-b;
});
1-which is and which is b
2-how execution goes (i mean which value will be compare with which one in order?
help shall be highly appreciated.
JavaScript Array sort () Method The sort () method sorts the items of an array. The sort order can be either alphabetic or numeric, and either ascending (up) or descending (down). By default, the sort () method sorts the values as strings in alphabetical and ascending order.