方式一

Array.prototype.unique3 = function()
{
    var n = [this[0]]; //结果数组
    for(var i = 1; i < this.length; i++) //从第二项开始遍历
    {
        //如果当前数组的第i项在当前数组中第一次出现的位置不是i,
        //那么表示第i项是重复的,忽略掉。否则存入结果数组
        if (this.indexOf(this[i]) == i) n.push(this[i]);
    }
    return n;
}




方式二


Array.prototype.unique2 = function()  
{  
    var n = {}, r = [], len = this.length, val, type;  
    for (var i = 0; i < this.length; i++) {  
        val = this[i];  
        type = typeof val;  
        if (!n[val]) {  
            n[val] = [type];  
            r.push(val);  
        } else if (n[val].indexOf(type) < 0) {  
            n[val].push(type);  
            r.push(val);  
        }  
    }  
    return r;  
}




方式三

Array.prototype.unique1 = function () {
  var n = []; //一个新的临时数组
  for (var i = 0; i < this.length; i++) //遍历当前数组
  {
    //如果当前数组的第i已经保存进了临时数组,那么跳过,
    //否则把当前项push到临时数组里面
    if (n.indexOf(this[i]) == -1) n.push(this[i]);
  }
  return n;
}




参考资料:js数组去重复   http://www.studyofnet.com/news/888.html