var sourceA = [{ pid: 1, data_a: 23, data_x: 23},{ pid: 2, data_a: 23 ,data_x: 23}];
var sourceB = [{ pid: 1, data_a: 34, data_x: 34 },{ pid: 2, data_a: 34, data_x: 34 }];
var sourceC = [{ pid: 1, data_a: 35, data_x: 34 },{ pid: 2, data_a: 35, data_x: 34 }];
I am getting following data from multiple source. In those object there is a field PID which one is common. So , I want to combined it according to PID.
Expected output :
var p = [{
"pid": 1,
"array": [{"data_a": 33,"data_x": 30},{"data_a": 33,"data_x": 30},{"data_a": 33,"data_x": 30}]
},{
"pid": 2,
"array": [{"data_a": 33,"data_x": 30},{"data_a": 33,"data_x": 30},{"data_a": 33,"data_x": 30}]
}]
I tried with following
var result = sourceA.map((obj, index) => Object.assign({}, sourceA[index], sourceB[index], sourceC[index]));
But I am not getting what I expected. then I tried with How to group array of objects by key But My source is 3 not 1.