JS array element Size Sort instance Code

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.