Deduplication Array The most common way I sum up, the other is not commonly do not write

Mounted () {
     // Array to retest 
    // performance 1.set es6 cycle performance no2 little higher than for 
    the let ARR = [10,8,7,5,1,2,3,8,7,11 ] 
    Console .log (ARR, arr.length, 'initial array' );
     // the console.log (Array.from (the Set new new (ARR))); // Array.from () method is an array of objects or may traverse the class object is converted into a real array. 

    // 2.For loop de-emphasis (sorted after the first idea is to compare) the performance of NO3 
    // the let arr.sort AA = () 
    // the let CC = [] 
    // the console.log (AA); // [. 1, 10 ,. 11, 2,. 3,. 5,. 7,. 7,. 8,. 8] 
    // for (the let I = 0; I <aa.length; I ++) { 
    //    ! IF (AA [I] AA = [I +. 1 ]) { 
    //      cc.push (AA [I]) 
    //    } 
    // } 
    //console.log (cc); // [1 , 10, 11, 2, 3, 5, 7, 8] to get a weight 
    / *  
    for ... of statement creates a loop iteration to iteration objects. Introduced in ES6 for ... of the loop, instead of for ... in and forEach (), and support the new protocol iteration. 
    for ... of Arrays, allows you to traverse (arrays), Strings (string), Maps (mapping), Sets (set) and the like can be iterative data structure 
    can facilitate the object, it can be converted into an array with array.from for of 
    * / 

/ *      //. 3 for the highest ... + object of performance performance No1   
// first create an empty object, and then loop through for, using the object attribute of this feature will not be repeated, checking whether the array element is repeated 
    let = Result [] 
    the let obj = {} 
    for (I of the let ARR) { 
        IF (! obj [I]) { 
            result.push (I) 
            obj [I] = 'I is the value of the attribute' 
            // obj [I] = 'whatever you want to write what you write what ah' 
            console.log (obj, '00000000000')  
          // print will know ah, such obj = {10: 1,8: 1 similar name: 'lbj', name: 'wade' using the object attribute uniqueness deduplication}} 
        }
    } 
    The console.log (Result, '66,666,666,666'); // [10,. 8,. 7,. 5,. 1, 2,. 3,. 11] get * / 

        // . 4 and includes the performance for the cycle is not recommended to only provide downwards idea 
        let gg = []
         for (the let I = 0; I <arr.length; I ++ ) {
           IF (! {gg.includes (ARR [I])) 
            gg.push (ARR [I]) 
          } 
        } 
        the console.log (GG, 'GG' ); 
        

  }

https://www.cnblogs.com/wisewrong/p/9642264.html this writing time-consuming can look at

Recommended new Set and uniqueness of the object is not to re-explain

Guess you like

Origin www.cnblogs.com/myfirstboke/p/11228277.html