6
There is the function sort, but it sort from minor to major, and I’d like to sort from major to minor. There’s some function in javascript for that?
Code with sort:
var numeros = [200,100,400,900,600,700];
numeros.sort();
for(i = 0 ; i < numeros.length; i++){
$("ul#ul-numeros").append('<li>' + numeros[i] + '</li>');
}
<ul id="ul-numeros">
</ul>
Thank you very much ...
– Maria
+1. As a complement, it may be useful to clarify, for those who do not know, how the method parameter
sortworks (i.e. when comparing two elements, returns a negative value ifashould appear beforeb, a positive value if otherwise, and0if both are equal or equivalent).– mgibsonbr
@mgibsonbr edited and put your explanation, thank you!
– user6026