日期:2014-05-16  浏览次数:20311 次

js 去除数据重复数据
如题:
-------------
       Array.prototype.distinct = function() {
		        var ret = [];
		        for (var i = 0; i < this.length; i++) {
		         for (var j = i+1; j < this.length;) {
		             if (this[i].id === this[j].id) {
		                 ret.push(this.splice(j, 1)[0]);
		             } else {
		                 j++;
		             }
		         }
		        }
		        return ret;
	}

说明:此实例数组类型为
var values =new Object();
values.id= getValues[i].id;
values.text= getValues[i].text;
values.checked="1";

所以:判断条件为  if (this[i].id === this[j].id)
如果数据类型为
var s = [1,2,3····n];
则,修改为
if (this[i] === this[j])
即可!