This article provides four kinds of JS code to remove repeating array elements, four functions The simplest way to delete a repeating array element is a regular expression.
<!doctype HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd "" <html xmlns= "http://www.jzread.com/1999/xhtml" <head> < Meta http-equiv= "Content-type" content= "HTML; charset=gb2312 "/> <title>js Remove duplicates in an array </title> <script> Function Unique (data) { data = Data | | []; var a = {}; len = data.length; for (var i=0; i<len;i++) { var v = data[i]; if (typeof (A[v]) = = ' undefined ') { a[v] = 1; } }; data.length=0; for (var i in a) { data[data.length] = i; } return data; } Function Test () { var arr = [9,1,3,8,7,7,6,6,5,7,8,8,7,4,3,1]; var arr1 = unique (arr); alert (Arr1.join (",")); } Test (); </script> //Method two
<script language= "Web Effects" > function Getnorepeat () { Return Arguments[0].join (' ‖ '). Match (/(b[^‖]+b) (?!. *‖1B)/ig); } var Tmparr = [1, ' A ', ' AB ', ' abc ', ' d ', 1.2, ' a+b ', ' d ', ' e ', 5, ' www.jzread.com ', 1, ' H ', ' C ', ' AB ']; var Retarr = getnorepeat (Tmparr); alert (Retarr); </script> Method Three
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.