通过map一次拿出数组中,筛选某个属性一样,所有重复和不重复的对象

vue方法,longitude相同下,使用map做区分,打印arr1和arr2

deletesame() {
      let arr = [
        {
          key: 1,
          rootId: "33030200992007000001",
          gbId: "33032796091320002029",
          parentGbId: "330300000000",
          parentName: "市本级",
          name: "QS温州成鸿铝塑有限公司-通道处(环保)",
          manufacturer: null,
          model: "1",
          firmware: null,
          longitude: "120.448293",
          latitude: "27.535628",
          mark: 6,
          status: 2,
          videoSource: "温州雪亮工程",
          videoProtocol: "雪亮私有接口",
        },
        {
          key: 2,
          rootId: "33030200992007000001",
          gbId: "33032796091320002030",
          parentGbId: "330300000000",
          parentName: "市本级",
          name: "QS(环评鉴定为非危废)温州格洛博电子有限公司-通道一(环保)",
          manufacturer: null,
          model: "1",
          firmware: null,
          longitude: "120.615262",
          latitude: "27.516405",
          mark: 6,
          status: 1,
          videoSource: "温州雪亮工程",
          videoProtocol: "雪亮私有接口",
        },
        {
          key: 3,
          rootId: "33030200992007000001",
          gbId: "33032796091320002031",
          parentGbId: "330300000000",
          parentName: "市本级",
          name: "QS(环评鉴定为非危废)温州格洛博电子有限公司-通道二(环保)",
          manufacturer: null,
          model: "1",
          firmware: null,
          longitude: "120.616262",
          latitude: "27.516405",
          mark: 6,
          status: 1,
          videoSource: "温州雪亮工程",
          videoProtocol: "雪亮私有接口",
        },
        {
          key: 4,
          rootId: "33030200992007000001",
          gbId: "33032796091320002032",
          parentGbId: "330300000000",
          parentName: "市本级",
          name: "QS温州信德电力配件有限公司-通道三(环保)",
          manufacturer: null,
          model: "1",
          firmware: null,
          longitude: "120.444538",
          latitude: "27.538631",
          mark: 6,
          status: 2,
          videoSource: "温州雪亮工程",
          videoProtocol: "雪亮私有接口",
        },
      ];

      let map = new Map();
      let arr1 = [];
      let arr2 = [];
      let list = [];
      arr.forEach((item, index) => {
        if (!map.has(item.longitude)) {
          map.set(item.longitude, index);
          arr1.push(item);
        } else {
          arr2.push(item);
        }
      });
      console.log(arr1)
      console.log(arr2)

      list = [...arr1, ...arr2];
      return list;
    }
    ```

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

知知洋洋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值