Home > Web Front-end > JS Tutorial > body text

Sample code for JS array deduplication and deduplication_javascript skills

WBOY
Release: 2016-05-16 17:02:55
Original
1261 people have browsed it
Method 1: Remove duplicate data
Copy the code The code is as follows:

<script><br>Array.prototype.distinct=function(){<br>var a=[],b=[];<br>for(var prop in this){<br> var d = this[prop];<br> if (d===a[prop]) continue; //Prevent looping to prototype<br> if (b[d]!=1){<br> a. push(d);<br> b[d]=1;<br> }<br>}<br>return a;<br>}<br>var x=['a','b','c ','d','b','a','e','a','b','c','d','b','a','e'];<br> document.write('Original array:' x);<br>document.write("<br />");<br>document.write('After deduplication:' x.distinct());<br></script>

Method 2: Get duplicate data
Copy Code The code is as follows:


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!