我想匹配兩個json文件的id並返回匹配的對象。這些都是2 JSON文件:如何根據匹配的ID返回一個對象數組?
{
"een": {
"id": "100",
"title": "Entertainment and stuff"
},
"twee": {
"id": "107",
"title": "Sport for everyone"
},
"drie": {
"id": "108",
"title": "Eating is good"
}
}
這是第二個:
[
{
"name": "Entertainment",
"id": "100",
"price": 2600,
"gifted": false
},
{
"name": "Sport",
"id": "107",
"price": 2500,
"gifted": false
}
]
由於2個匹配idvalues的結果,我應該得到:
[
{
"name": "Entertainment",
"id": "100",
"price": 2600,
"gifted": false,
"title": "Entertainment and stuff"
},
{
"name": "Sport",
"id": "107",
"price": 2500,
"gifted": false,
"title": "Sport for everyone"
}
]
我在想,如果有一種奇特的方式使用lodash或其他東西,並以一個很好的緊湊方式做到這一點?
您錯過了最後一步。我認爲OP只想合併那些id匹配的對象。所以你的結果應該以某種方式忽略id爲108的對象。 – jusopi
我的不好。感謝您指出了這一點。 –