An array of deduplication solutions

The first

<Script>
     var ARR = [1,1,2,2,5,4,3,4,3,5,6,6,8,8,9,9]; // analog data array 
    for ( var I = 0; I <arr.length; I ++ ) {
         for ( var J = I +. 1; J <arr.length; J ++) { // double nested loop for traversal 
            IF (ARR [I] === ARR [J] ) { 
                arr.splice (J, 1); // duplicate by weight to the splice will change the original array 
            } 
        } 
    } 
    the console.log (ARR) // print a new array of de-duplicated [1, 2, 5, 4 ,. 3,. 6,. 8,. 9] 
</ Script>

For ... of the second de-emphasis, de-emphasis of a scheme fast giant

<Script>
     var ARR = [1,1,2,2,5,4,3,4,3,5,6,6,8,8,9,9]; // analog data array 
       var Result = [] ; 
       the let obj = []; // do not use duplicate object characteristics
        for (I of the let ARR) {
         IF (! {obj [I]) 
            result.push (I) 
            obj [I] =. 1 ; 
        } 
    } 
    Console. log (Result)
 </ Script>

A third method of providing the set es6

<Script>
     var ARR = [1,1,2,2,5,4,3,4,3,5,6,6,8,8,9,9]; // analog data array 
    var SS = new new the Set (ARR); // return an object to a weight after 
    the console.log (Array.from (SS));   // Array.from into an array 
</ script>

 

Guess you like

Origin www.cnblogs.com/skydragonli/p/11391078.html