下面使用JS来去掉数组中重复的元素,返回不重复,主要用unique,看例子:

Code
[http://www.xueit.com]
<!doctype html>
<html dir="ltr" lang="zh-CN">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=7">
<title>unique函数 By 司徒正美</title>
<script>
Array.prototype.inArray = function(el){
for (var i=0,n=this.length;i<n;i )
if(this[i]===el)return true;
return false;
}
Array.prototype.unique = function() {//取数组中唯一的元素并放进新数组中返回
var i = 0, n = this.length,ret = [];
for (; i < n; i )
if (!ret.inArray(this[i])) ret.push(this[i]);
return ret;
};
var ret= ["span","span","strong","span","b"]
alert(ret.unique())
</script>
</head>
<body>
</body>
</html>