zoukankan      html  css  js  c++  java
  • 数组中对象去重

    let coupons=[ { "id": 95, "appId": "mitang", "deleted": false, "creator": null, "created": 1520560522000, "modifier": null, "modified": 1520560522000, "pageSize": null, "offset": null, "type": 1, "typeId": 76, "userId": 108, "guideId": 32216, "storeId": null, "couponId": 3, "couponSn": "mt0000000001", "startTime": 1520560522000, "endTime": 1520560522000, "couponName": "发生的发生", "remark": "", "couponPackId": null, "writeOff": 0, "face": "10" }, { "id": 95, "appId": "mitang", "deleted": false, "creator": null, "created": 1520560522000, "modifier": null, "modified": 1520560522000, "pageSize": null, "offset": null, "type": 1, "typeId": 76, "userId": 108, "guideId": 32216, "storeId": null, "couponId": 3, "couponSn": "mt0000000001", "startTime": 1520560522000, "endTime": 1520560522000, "couponName": "发生的发生", "remark": "", "couponPackId": null, "writeOff": 0, "face": "10" } ]
    let unique = {};
    coupons.forEach(function (gpa) {
    unique[JSON.stringify(gpa)] = gpa
    });
    coupons = Object.keys(unique).map(function (u) {
    return JSON.parse(u)
    });

      数组中不支持直接比较对象;

  • 相关阅读:
    第13讲——使用类
    第12讲——对象和类
    第11讲——面向对象编程
    第10讲——名称空间
    数论19——高斯消元
    贪心思想
    重要的转变(感觉自己最近堕落必读)
    java面试
    Java泛型
    系统设计
  • 原文地址:https://www.cnblogs.com/shuaitong/p/8583088.html
Copyright © 2011-2022 走看看