About JS array de-weight

Source: Internet
Author: User

Tag:font    Otherwise     start    cti    save     style    traversal     representation    mil   

    1. Array.prototype.unique1 = function () {var n = [];//A new temporary array for (var i = 0; i < this.length; i++)//traverse the current array {//If the current array is already insured Save in a temporary array, skip,//Otherwise push the current item into the temporary array if (N.indexof (this[i]) = = 1) n.push (This[i]);} return n;}
    2. Array.prototype.unique2 = function () {var n = {},r=[];//n is a hash table, r is a temporary array for (var i = 0; i < this.length; i++)//traverse the current array {if (!n[this[i])//If the hash table does not have the current item {N[this[i]] = true;//hash Table R.push (this[i]);//Push the current item of the current array into the temporary array}}return R;
    3. Array.prototype.unique3 = function () {var n = [this[0]];//result array for (var i = 1; i < this.length; i++)//start with the second entry {//if the current array The first occurrence of item I in the current array is not i,//so it means that item I is duplicated and ignored. Otherwise deposit the result array if (This.indexof (this[i]) = = i) N.push (This[i]);} return n;}

About JS array de-weight

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.