Sort JavaScript Array-----1

Source: Internet
Author: User
Tags javascript array

1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 <Head>4     <MetaCharSet= "UTF-8">5     <title>JavaScript array de-weight algorithm-----3</title>6 </Head>7 <Body>8     <Script>9 varArrdemo= NewArray ();Ten  One arrdemo[0] = Ten; A arrdemo[1] =  -; - arrdemo[2] = Wuyi; - arrdemo[3] =  -; the  - Arrdemo.sort ();//when the sort method is called, the array itself is changed, which affects the original array -  - Console.log (Arrdemo);//10,100,50,51 By default the sort method is sorted in ASCII alphabetical order, not what we think is sorted by number size +  - Arrdemo.sort (function(A, b) {returna>b?1:-1});//sort from small to large +  A Console.log (Arrdemo);//10,50,51,100 at  - Arrdemo.sort (function(A, b) {returna<b?1:-1});//sort from big to small -  - Console.log (Arrdemo); -     </Script> - </Body> in </HTML>

Sort JavaScript Array-----1

Related Article

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.