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