Js 去掉 数组(new Array())中重复 数据
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Array Unique </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
//去掉数组 重复的项
Array.prototype.unique = function()
{
var a = {};
for(var i=0; i<this.length; i++)
{
if(typeof a[this[i]] == "undefined")
a[this[i]] = 1;
}
this.length = 0;
for(var i in a)
this[this.length] = i;
return this;
}
var arrays = new Array();
arrays.push("1");
arrays.push("2");
arrays.push("3");
arrays.push("1");
arrays.push("2");
arrays.push("1");
alert("原始数组长度:"+arrays.length);
//去掉重复数据
arrays.unique();
alert("去掉重复数据后的数组长度:"+arrays.length); //-->
</SCRIPT>
</BODY>
</HTML>