假设我有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();
我做错了什么?