I have 2 arrays of objects:
var a = [
{ "image_id": 631293, "score": 73 },
{ "image_id": 11848407, "score": 56 }
];
var b = [
{ "image_id": 631293, "article_id": 173 },
{ "image_id": 11848407, "article_id": 121 }
];
I have tried to apply method described in How can i merge array of objects with underscore js but unfortunately it does not work at all.
My need is to merge both arrays of objects thanks to image_id
.
So I tried this :
_.values(
_.extendOwn(
_.indexBy(a, 'image_id'),
_.indexBy(b, 'image_id')
)
)
but output just return me this array of object a
I need to get :
[
{"image_id": 631293, "score": 73, "article_id": 173},
{"image_id": 11848407, "score": 56, "article_id": 121}
]
How can I achieve this without doing a loop to check every element of array and use a findWhere
?