I'm trying to change some properties in the first array of objects based on the second array of objects
here is the first one
const data1 = [
{
type: 'text',
message: 'Hi',
area: 'A',
},
{
type: 'text',
message: 'Bye',
area: 'B',
},
{
type: 'text',
message: 'Yeah',
area: 'C',
},
];
and the second one is
const data2 = [
{
area: {
a: 1,
},
},
{
area: {
b: 2,
},
},
{
area: {
c: 3,
},
},
];
here is my expect result
const result = [
{
type: 'text',
message: 'Hi',
area: {
a: 1,
},
},
{
type: 'text',
message: 'Bye',
area: {
b: 2,
},
},
{
type: 'text',
message: 'Yeah',
area: {
c: 3,
},
},
];
This is what I've done so far,
let a = data1.map((item, idx) => {
return { ...item, ['area']: data2[idx] };
});
but it doesn't work as expected, please advice.