How can I change the following data structure that is coming from the api into the desired format that is defined below?
inspectionViewAllRs = [
{
INSPN_XFER_SEQ_NR: {
value: '5'
},
FNRL_FLG: {
label: 'No',
value: 'N'
},
HAS_PAST_INSPN: {
value: '3'
},
MTG_CO_PHN_AREA_CD: {
value: ''
},
DECLARATION_CD: {
label: 'US Citizen/Non-Citizen National',
value: 'CZ'
},
....
....
....
},
{ ... }
{ ... }
{ ... }
]
How can I just convert it into this an array of objects format?
inspectionViewAllRs = [
{ label: "", value: '5' },
{ label: "No", value: "N" },
{ label: "", value: "3" },
{ label: "", value: "" },
{ label: "US Citizen/Non-Citizen National", value: "CZ" },
....
....
....
]
I tried to do the following but this doesn't help much:
if(!_.isEmpty(this.state.inspectionViewAllRsData)) {
const result = this.state.inspectionViewAllRsData.map((data, i) => {
const items = Object.values(data);
const newItem = {}
newItem.label = items[i].label;
newItem.value = items[i].value;
return newItem
})
console.log("result ", result)
// this is what I see printed out in console log
// result (5) [{…}, {…}, {…}, {…}, {…}]
0: {label: undefined, value: "5"}
1: {label: "No", value: "N"}
2: {label: undefined, value: "3"}
3: {label: undefined, value: ""}
4: {label: "", value: ""}
length: 5
}
Why am I not getting return all the rest of the data?