JS array element Size ordering instance code:
In practical applications, it is sometimes necessary to sort the elements of an array by size, of course, there are a number of methods to sort first, such as using the sort () method of the array object itself, and this chapter will share another way to look at the code example first:
varorg=[5,4,3,2,1,6,7,9,8,10]; varTemparr=NewArray (); for(vari=0;i<org.length;i++) { if(i==0) {temparr[0]=ORG[0];//Put the first element in a new sequence } Else { for(varj=0;j<temparr.length;j++) { if(org[i]>Temparr[j]) { //if it is the last element of the new sequence, insert if(j==temparr.length-1) {temparr[j+1]=Org[i]; Break; } Else //if it is not the last element, move backward { Continue; } } Else { //move the new sequence, and then insert for(vark=temparr.length-1;k>=j;k--) {temparr[k+1]=Temparr[k]; } Temparr[j]=Org[i]; Break; }}}} Console.log (Temparr);
The above code can output sorted array content, here is not much introduced, if any problem can be thread message.
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=9283
For more information, refer to: http://www.softwhy.com/javascript/
JS array element Size Sort instance Code