var array = [{id:1,name:'jack'},{id:3,name:'tom'},{id:3,name:'liwei'},{id:5,name:'lkiki'},{id:5,name:'opoi'},{id:7,name:'lily'}];
var hash = {};
array = array.reduce(function (item, next) {
hash[next.id] ? '' : hash[next.id] = true && item.push(next);
return item;
}, []);
console.log(array);
说明:array数组里面有5个对象,其中第二个{id:3,name:'tom'}
和第三个{id:3,name:'liwei'}
中的id属性重复,如果id是判断对象重复的条件,那么使用array.reduce()方法进行去重,运行结果如下
如上红框里面只有4个对象