Take a look at this interesting code snippet:
let data1 = {a50: "PTP-1",b51: "09+75",c52: "112D",d53: "60.745",e54: "72.698",f55: "72.695",g56: "0.003",h57: null,i58: null, j59: "68.918", k60: null}
let data2 = [{ipid:'50', type:'Constant'},{ipid:'51', type:'Constant'},{ipid:'52', type:'Constant'},{ipid:'53', type:'Constant'},{ipid:'54', type:'Constant'},{ipid:'55', type:'Constant'},{ipid:'56', type:'Constant'},{ipid:'57', type:'Variable'},{ipid:'58', type:'Variable'},{ipid:'59', type:'Variable'},{ipid:'60', type:'Variable'}]
let results = [],
key = '';
for(key in data1){
if(data1.hasOwnProperty(key)){
let currentElement = data2.filter(function(element){
return element.ipid == key.substr(1)
});
for(let i = 0; i < currentElement.length; i++){
let temporaryData = {
ipid: currentElement[i].ipid,
type: currentElement[i].type
}
temporaryData[key] = data1[key];
results.push(temporaryData);
}
}
}
The above code generates the following outcome:
[
{"ipid": "50", "type": "Constant", "a50": "PTP-1"},
{"ipid": "51", "type": "Constant", "b51": "09+75"},
{"ipid": "52", "type": "Constant", "c52": "112D"},
{"ipid": "53", "type": "Constant", "d53": "60.745"},
{"ipid": "54", "type": "Constant", "e54": "72.698"},
{"ipid": "55", "type": "Constant", "f55": "72.695"},
{"ipid": "56", "type": "Constant", "g56": "0.003"},
{"ipid": "57", "type": "Variable", "h57": null},
{"ipid": "58", "type": "Variable", "i58": null},
{"ipid": "59", "type": "Variable", "j59": "68.918"},
{"ipid": "60", "type": "Variable", "k60": null}
]