I am trying to flatten an array with multiple objects inside my array. It keeps flatting it into one single array. I want it to have multiple objects inside the array but also want everything flatten with the everything removed except the keys and the values.
This is the current array named "livedata".
[
{
"earningsFileId": {
"value": 1234
},
"paymentType": {
"value": "Session",
"errors": [
{
"id": 802462,
"message": "Invalid Combination",
"status": "Processing"
}
]
},
"detailStatus": {
"value": "Processing"
}
},
{
"earningsFileId": {
"value": 5678
},
"paymentType": {
"value": "Session",
"errors": [
{
"id": 802462,
"message": "Invalid Combination",
"status": "Processing"
}
]
},
"detailStatus": {
"value": "Processing"
}
}
]
This is the output I am trying to achieve.
[
{
"earningsFileId": 1234,
"paymentType": "Session",
"detailStatus": "Processing"
},
{
"earningsFileId": 1234,
"paymentType": "Session",
"detailStatus": "Processing"
}
]
data = [];
Object.values(livedata).map((value, keys) => {
Object.keys(value).forEach((key) => {
data[key] = livedata[keys][key]['value']
})
});