My first array called feeds:
[
{
_id: '5b8906e81248270685399a9a',
name: 'fin24',
state: 'OK',
status: true,
},
{
_id: '5b8907031248270685399a9b',
name: 'news24',
state: 'OK',
status: true,
}
]
My second Array called feedArticlesCount:
feedArticlesCount: [
{ _id: 5b8907031248270685399a9b,
pending: 21,
approved: 1,
active: 21,
inactive: 1 },
{ _id: 5b8906e81248270685399a9a,
pending: 20,
approved: 0,
active: 20,
inactive: 0 },
{ _id: 5b8664c26d90b107d0952cbe,
pending: 62,
approved: 8,
active: 0,
inactive: 70 },
{ _id: 5b865bf28152610775987d67,
pending: 111,
approved: 30,
active: 0,
inactive: 141 }
]
I want to combine these both two arrays into one based on matching _id value, if _id not exist in first array i want to skip that.
My Expected output:
[
{
_id: '5b8906e81248270685399a9a',
name: 'fin24',
state: 'OK',
status: true,
pending: 20,
approved: 0,
active: 20,
inactive: 0
},
{
_id: '5b8907031248270685399a9b',
name: 'news24',
state: 'OK',
status: true,
pending: 21,
approved: 1,
active: 21,
inactive: 1
}
]
I tried with forEach and reduce method, but its not working correctly
Here i tried:
let result = [];
feeds.forEach((itm, i) => {
result.push(Object.assign({}, itm, feedArticlesCount[i]));
});
console.log(result);
This is working but my name key is storing in wrong _id place.