JavaScript sort() method by default sorts the array elements as strings in alphabetical and ascending order.
[19, 32, 34, 4, 6];
The "4" is bigger than "19" because "4" is bigger than "1".
You can fix this by providing the 'compareFix' parameters. For example:
n.sort( function(a,b) {return a-b} )
the result of following will be:
[4, 6, 19, 32, 34]
Login in to like
Login in to comment