i have a grouped array like this
this.state.tableData=
[0:{key: "EMAIL",val: ["[email protected]", "[email protected]", "[email protected]"]}
1:{key: "LASTNAME",val: ["Smith", "Pierce", "Paige"]}
2:{key: "FIRSTNAME",val: ["John", "Harry", "Howard"]}
3:{key: "SMS",val: ["33123456789", "33111222222", "33777888898"]}
]
i want to convert it to normal array like
0: {EMAIL: "[email protected]", LASTNAME: "Smith", FIRSTNAME: "John", SMS: "33123456789"}
1: {EMAIL: "[email protected]", LASTNAME: "Pierce", FIRSTNAME: "Harry", SMS: "33111222222"}
2: {EMAIL: "[email protected]", LASTNAME: "Paige", FIRSTNAME: "Howard", SMS: "33777888898"}
i have tried following code
this.state.csvHeaders=["EMAIL','FIRSTNAME','LASTNAME']
var contacts=[];
this.state.tableData.map(k => {
k.val.map(r => {
Object.keys(this.state.csvHeaders).forEach(key => {
if(k.val["Col"]==="EMAIL")
{
contacts[key]['EMAIL']=r;
}
})
})
})
but it doesnt work .... any suggestion what more can i modified .how can i store , push them to array ?
["Smith", "Pierce", "Paige", Col: "LASTNAME"]- the partCol: "LASTNAME"is not a proper array element. Please edit your question with the correct data structures