This article mainly introduces the implementation analysis of JavaScript array sorting applets. The example code is introduced in this article in detail, which has certain reference value for everyone's learning or work. Friends who need it can refer to it.
The sort() function of JavaScript array is sorted by string size. It cannot sort a set of numbers correctly. The following applet implements the function of sorting a set of numbers through a self-compiled function.
<script> function mysort(a){ var n=; var newa=[]; var temp; for(var i=0;i<n;i++) { for(var j=i;j<n;j++) { if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } (a[i]); } return newa; } arr=[1,9,5,3,7]; narr=mysort(arr); (narr); </script>
The running results of the program are as follows:
Array(5) [ 1, 3, 5, 7, 9 ]
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.