I have two arrays like below:
const array1 = [
{ type: 'BA', value: 100 },
{ type: 'CA', value: 200 },
];
const array2 = [
{
NameBA: 'STANDARD',
NameDescriptionBA: 'STANDARD',
AgeBA: 0,
NameCA: 'STANDARD',
NameDescriptionCA: 'STANDARD',
AgeCA: 0,
},
]
The array1 has the type value 'BA', I have to find the array2 keys last 2 characters includes with the array1 type value 'BA' and merge to the related object of array1.
My expected result is
cosnt array1 = [
{
type: 'BA',
value: 100,
NameBA: 'STANDARD',
NameDescriptionBA: 'STANDARD',
AgeBA: 0,
},
{
type: 'CA',
value: 200,
NameCA: 'STANDARD',
NameDescriptionCA: 'STANDARD',
AgeCA: 0,
},
]
I tried the below method but the output is incorrect
const keys = Object.keys(array2[0]);
array1.map(a => {
keys.map(b => {
if (b.includes(a.type)) {
array2.map(c => {
a.b = c.b
})
}
});
});