Array deduplication Array, Array deduplication Array

Source: Internet
Author: User

Array deduplication Array, Array deduplication Array

var aee3=[31,42,13,19,5,11,8,13,40,39,1,8,44,15,3];        Array.prototype.unqu2=function(){          this.sort();          var arr2=[this[0]];          for (var j = 1; j < this.length; j++) {               if(this[j]!=arr2[arr2.length-1]){                   arr2.push(this[j]);              }           };           return arr2;        }         Array.prototype.unqu3=function(){            var arr=[];            lable:for (var i = 0; i < this.length; i++) {                for (var j = 0; j < arr.length; j++) {                  if(this[i]==arr[j]){                       continue lable;                  }                };                arr[arr.length]=this[i];            };            return arr;        }                    Array.prototype.unqu=function(){            var n={},arr2=[];               for (var i = 0; i < this.length; i++) {                 if(!n[this[i]]){                     n[this[i]]=true;                     arr2.push(this[i]);                  }               };                  return arr2;         }         console.log(aee3.unqu());

There are a lot of de-duplication methods on the Internet, and the most stupid is the second method, and the best efficiency is the third one.

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.