JavaScript array de-weight algorithm-----5

Source: Internet
Author: User

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     vararr= [1,1,2,2,3,2,2,3,3,1,1,4,4,5,6];Ten     functionUnique (array) { One          for (varI= 0; I<array.length; I++) { A              for (varJ=I+1; J<Array.Length; J++) { -                 if(Array[i]==Array[j]) { - Array.splice (J--,1); the                     //Array.splice (--j,1);//Error Statement -                     //j--; -                 }; -             } +         } -         returnArray; +     } A varcc=unique (arr); at Console.log (cc) - //here involves the first throw value after the operation and the first operation after the value of the knowledge point, and the inside loop is a bit confusing, the internal loop, each encounter the same item, the subsequent removal of an item, with the splice (position, number, [replace element]) method, each operation of the array, the length of the array is changed, -     </Script> - </Body> - </HTML>

JavaScript array de-weight algorithm-----5

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.