I am a JavaScript beginner. I want to merge a nested array with "id" <-- unique for all the array of objects. The A and B keys are dynamic (ex. A, B, C, D, and so on) and can be added later. Whereas the dummy key is of a kind where if the dummy value of all the 3 arrays matches then only it will show in the final result; else it will show as - (hyphen)
let arr1 = [
{
A: 0.71,
B: 0.52,
id: 1,
dummy: 1,
},
{
A: 0.72,
B: 0.50,
id: 2,
dummy: 1,
},
];
let arr2 = [
{
A: 0.157,
B: 0.02255,
id: 1,
dummy: 1,
},
{
A: 0.16761,
B: 0.028281,
id: 2,
dummy: 1,
},
];
let arr3 = [
{
A: 0.55,
B: 0.50,
id: 1,
dummy: 1,
},
{
A: 0.5,
B: 0.43,
id: 2,
dummy: 1,
},
];
I want these in one array as finalArray with contains id and all the three arrays inside those with their respective ids
let finalArr = [
{
id: 1,
dummy: 1,
arr1_A: 0.71,
arr1_B: 0.52,
arr2_A: 0.157,
arr2_B: 0.02255,
arr3_A: 0.55,
arr3_B: 0.5,
},
{
id: 2,
dummy: 1,
arr1_A: 0.72,
arr1_B: 0.5,
arr2_A: 0.16761,
arr2_B: 0.028281,
arr3_A: 0.5,
arr3_B: 0.43,
},
];
arrfollowed by a consecutive number?