I have a data structure like this:
data = [
{
parent: {name: 'Sheet'},
firstArray: [{sampleVar: 0.3, typeName: 'active'}, {sampleVar: 0.4, typeName: 'active'}],
secondArray: [{sampleVar: 1.2, typeName: 'passive'}, {sampleVar: 1.3 , typeName: 'passive'}]
},...
]
I want to transform it to a tree data like this:
treeData = [
{
parent: {
name: 'Sheet',
children: [{
typeName: 'active',
children: [
{sampleVar: 0.3},
{sampleVar: 0.4}
]
},
{
typeName: 'passive',
children: [
{sampleVar: 1.2},
{sampleVar: 1.3}
]
},...
]
},...
}
];
I have to mention that my variable typeName has the same value for each array. Does anyone know a good approach to achieve this?