In order to properly display multiple tables in my Angular project, I am looking to convert an object type into an array of different objects. The object I am working with is as follows:
let myObject = {
internalValue:{city:"Paris", country:"France", pinCode:12345},
originalValue:{city:"Nantes", country:"France", pinCode:34567},
score:{city:10, country:100, pinCode:45}
};
The desired output array should look like this:
[
[
{detail:"Paris", label:"internalValue"},
{detail:"Nantes", label:"originalValue"},
{detail:10, label:"score"}
],
[
{detail:"France", label:"internalValue"},
{detail:"France", label:"originalValue"},
{detail:100, label:"score"}
],
[
{detail:12345, label:"internalValue"},
{detail:34567, label:"originalValue"},
{detail:45, label:"score"}
]
]
Currently, the code I have written for this transformation is as follows:
let tableData:any;
tableData = _.transform(myObject, result, value, key)=>{
let retValue:any;
_.forIn(value, (v,k)=> {
let tempArr:Array<any>;
let tempObj:any = {};
tempObj.detail= v;
tempObj.label=key;
tempArr.push(tempObj);
retValue.push(tempArr);
})
result = [...retValue];
return result;
},[]);
I seem to be stuck when it comes to moving on to the next set of loops.