主页 M

js过滤数组中重复的值

2014-11-12 网页编程网 网页编程网
<html>
<head>
<title>js过滤数组中重复 </title>
</head>
<body>
<script>
//过滤数组中重复 
var uniq = function (arr) {
var a = [], o = {}, i, v, len = arr.length;
if (len < 2) {
return arr;
}
for (i = 0; i < len; i++) {
v = arr[i];
if (o[v] !== 1) {
a.push(v);
o[v] = 1;
}
}
return a;
}
var x = new Array("www","dwwwcn","wwwdwwwcn","dwwwcn");
alert(x);
var y = uniq(x);
alert(y);
</script>
</body>
</html>
阅读原文
阅读 4056
123 显示电脑版