删除数组对象中重复的对象
var goodsList = [
{goods:{id:1},price:1,count:1},
{goods:{id:1},price:1,count:1},
{goods:{id:2},price:2,count:2},
{goods:{id:2},price:2,count:2}
];
for(var i=0; i<goodsList.length; i++){
var item = goodsList[i]
for(var j = i+1; j<goodsList.length; j++){
if(item.goods.id == goodsList[j].goods.id){
goodsList.splice(j,1)
i--
}
}
};
console.log(goodsList);
打印的结果如下图所示:
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。