How to remove repeated array elements in javascript [instance], javascript Array

Source: Internet
Author: User
Tags javascript array

How to remove repeated array elements in javascript [instance], javascript Array

In practical applications, we often need to remove repeated elements from the array. below is the implementation of de-duplication of javascript Arrays:

<Script language = "javascript"> <! --/* Method for determining whether an element exists in an array */function isExistInArr (_ array, _ element) {if (! _ Array |! _ Element) return false; if (! _ Array. length) {return (_ array = _ element);} for (var I = 0; I <_ array. length; I ++) {if (_ element = _ array [I]) return true;} return false ;} /* method for removing repeated elements in the array */function distinct (_ array) {if (! _ Array |! _ Array. length) return _ array; var newArray = new Array (); for (var I = 0; I <_ array. length; I ++) {var oEl = _ array [I]; if (! OEl | this. isExistInArr (newArray, oEl) continue; newArray [newArray. length] = oEl;} return newArray;} var origArr = [1, 2, 3, 4, 1, 3]; origArr = distinct (origArr); alert (origArr ); // --> </script>

The implementation method [Example] for removing array repeated elements in the above javascript is all the content shared by xiaobian. I hope to give you a reference, and I hope you can provide more support to the customer's house.

Related Article

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.