如何查看对象与lodash之间是否存在交集?

时间:2017-03-16 04:43:44

标签: javascript lodash

假设我有2个json对象,我想看看是否存在基于id的匹配/交集。这是两个对象:

 obj=   {
      "container_copy": {
        "card1": {
          "id": "300",
          "copy": "hello"
        },
        "card2": {
          "id": "1000",
          "type": "card"
        },
        "text": "bla"
      }
    }

   items= [{id:"103",text:'hello'}, {id:"11",text:'yo'}]

我试过了:

 let o1 = _.keyBy(_.values(obj), 'id');
 let o2 = _.keyBy(items, 'id');
 let inter = _.intersection(_.keys(o1), _.keys(o2));
 let result = _.chain(o1)
            .pick(inter)
            .merge(_.pick(o2, inter))
            .value();

我做错了什么?

0 个答案:

没有答案