1

删除数组对象中重复的对象

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);

打印的结果如下图所示:
在这里插入图片描述
在这里插入图片描述


Liu_xiaoqing
32 声望2 粉丝