I’m coding using javascript & react. I have an object named “rates” I’m trying to map through:
{
"M": {
"lab": {
"S": "50%"
},
"dme": {
"S": "75%"
},
"therapy": {
"S": "80%"
},
"radio": {
"S": "85%"
},
"drugs": {
"S": "100%"
}
}
}
Here’s how I’m mapping through it:
const rateList = rates.M.map(
(rate) => {
return {
"DME": {
S: rates.M.dme.S,
},
"Lab": {
S: rates.M.lab.S,
},
"Drugs": {
S: rates.M.drugs.S,
},
"Radio": {
S: rates.M.radio.S,
},
"Therapy": {
S: rates.M.therapy.S,
},
};
},
);
I keep on getting error “rates.M.map is not a function”. I’m assuming because “rates” is not an array but an object.
How should I remap? So the values from the object is displayed to its corresponding labels?
I appreciate your guidance!