I have an object which contains different arrays like
Fruits: Array(4),
Trees:Array(3),
Vegetables:Array(2),…etc.
I want to push all these arrays into one array and display them in separate accordions.
Before Combine Array:
{
Fruits: [{label:’Apple’, text:’Red Color’},{label:’Mango’, text:’Yellow Color’},{label:’Orange’, text:’Orange Color’},{label:’Grap’, text:’Black Color’}]
Trees: [{label:’Maple Tree’, text:’Orange Leafs’},{label:’Redbud Tree’, text:’Pink Leafs’},{label:’Pine’, text:Green Leafs’}]
Vegetables: [{label:’Tomato’, text:’Red Color’},{label:’PumpKin’, text:’Yellow Color’},{label:’Carrot’, text:’Orange Color’},{label:’Onion’, text:’Red Color’}]
}
I want to combine above arrays into one single array as below by using Typescript and display them in accordion. [
{label:Fruits, values:[ {label:’Apple’, text:’Red Color’},{label:’Mango’, text:’Yellow Color’}, {label:’Orange’, text:’Orange Color’},{label:’Grap’, text:’Black Color’}]},
{label:Trees, values:[{label:’Maple Tree’, text:’Orange Leafs’},{label:’Redbud Tree’, text:’Pink Leafs’},{label:’Pine’, text:Green Leafs’}]},
{label:Vegetables, values:[{label:’Tomato’, text:’Red Color’},{label:’PumpKin’, text:’Yellow Color’},{label:’Carrot’, text:’Orange Color’},{label:’Onion’, text:’Red Color’}]}
What I have tried:
I tried to add arrays by using foreach but no use. So i posted this. Any help regarding this.