JavaScript Sort by Pure number

Source: Internet
Author: User

Directly on the code:
1         varArr=[2{Name: "Walk", Age: "Sports", "basketball", Number: "231123"},3{Name: "Reese", Age: "3", Sports: "Piano", Number: "534563"},4{name: "Allen", Age: "Sports", "Volleyball", Number: "345455"},5{name: "Wang Wu", Age: "Sports", "Ping-Pong", Number: "867324"},6{Name: "Fatigue", Age: "Sports", "soccer", Number: "132457"}7         ];8 9         //single-digit sortingTen         //Console.log (arr.  Sort(sortdownage));//Positive Order One         //Console.log (Arr.sort (sortupage));//reverse Order A  -  -         //flexible Digital multi-sorting the         //Console.log (arr, "Age");//Positive Order -         //Console.log (arr, "age");//reverse Order -         // -         //Console.log (arr, "number");//Positive Order +         //Console.log (arr, "number");//reverse Order -  +          A          at          -          -         //A single, purely numeric sort, with a positive sequence above, and a reverse order below . -         functionSortdownage (A, b) { -             returnA.age-B.age -         } in  -         functionSortupage (A, b) { to             returnB.age-A.age +         } -  the//Pure Digital Flexible sequencing *         /*numbers are being sorted $         *Panax Notoginseng * Data: Object array - * P: Parameters for sorting the         * +         * */ A         functionsortdownnumber (data, p) { the              for(i = 0; i < data.length-1; i++) { +                  for(j = 0; J < data.length-1-I; j + +) { -                     if(Parsefloat (data[j][p]) > parsefloat (data[j + 1][p])) { $                         vartemp =Data[j]; $DATA[J] = data[j + 1]; -Data[j + 1] =temp; -                     } the                 } -             }Wuyi             returndata; the         } -  Wu  -         /*Digital Reverse order About          * $ * Data: Object array - * P: Parameters for sorting -          * -          * */ A         functionsortupnumber (data, p) { +              for(i = 0; i < data.length-1; i++) { the                  for(j = 0; J < data.length-1-I; j + +) { -                     if(Parsefloat (Data[j][p]) < parsefloat (data[j + 1][p])) { $                         vartemp =Data[j]; theDATA[J] = data[j + 1]; theData[j + 1] =temp; the                     } the                 } -             } in             returndata; the}

The results are shown separately:

 

1, a single numerical order, the left side is the positive sequence (Arr.sort (sortdownage)), the right side is reversed (Arr.sort (sortupage))

      

2, flexible digital multi-sequencing, left is the age of the positive sequence (Sortdownnumber (arr, "age")), the right side of the reverse order (Sortupnumber (arr, "ages"))

      

3, flexible number of multi-ordering, the left is a positive sequence (Sortdownnumber (arr, "number")), the right side is the numbers reverse order (Sortupnumber (arr, "number"))

      

    

  

This is the other sort of method, welcome to view, welcome to the comments!

Sort by JavaScript date

Sort by JavaScript non-numeric (Chinese)

  

JavaScript Sort by Pure number

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.