const yourObj = {
"confirmed": {
"value": 123456789,
"detail": "https://covid19.mathdro.id/api/confirmed"
},
"deaths": {
"value": 99999,
"detail": "https://covid19.mathdro.id/api/confirmed"
},
"recovered": {
"value": 8888,
"detail": "https://covid19.mathdro.id/api/confirmed"
}
}
const desiredKeys = Object.keys(yourObj)
const stats = desiredKeys.reduce((finalResult, desiredKey) => {
let temp = {}
temp.category = desiredKey
temp.value = yourObj[desiredKey].value
finalResult.push(temp);
return finalResult
}, [])
console.log(stats) //[{category: "confirmed", value: 123456789}, { category: "deaths", value: 9999}, { category: "recovered", value: 8888}]
//InfoPanel
function InfoPanel(){
return (
//more code on top
<Grid container spacing={3}>
stats.map(stat=> (
<Grid item xs={12} sm={4}>
<Paper className={classes.paper}>{stat.category}: {stat.value}</Paper>
</Grid>
))
</Grid>
//more code below
)}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…