I have these two arrays, I want to check if the titles and keys match and then push the count from typesCount into types.
I have tried to do a map within a map to check the values against each other and produce a new array but it has not worked.
const types = [
{
title: 'House',
slug: 'house',
count: 0,
},
{
title: 'Car',
slug: 'car',
count: 0,
},
{
title: 'Bike',
slug 'bike',
count: 0,
},
];
const typesCount = [
{
key: 'House',
count: '11',
},
{
key: 'Bike',
count: '22',
},
];
What I've tried so far
const checkForCount = typesCount.map( x => ({
types.map( y => ({
title: y.title,
slug: y.slug,
count: y.title === x.key : x.count ? y.count,
}));
}));