I've been playing with json objects & using ReactJS. One of the json object represented by variable 'res'. How do I convert 'res' into 'b'. I'm also getting my json object 'res' from an api.
I've reciprocated my problem over this link: https://codesandbox.io/s/epic-leaf-sznhx?file=/src/App.js
const [res, setResult] = useState();
useEffect(() => {
(async () => {
axios.get("https://corona.lmao.ninja/v2/countries").then(response => {
setResult(response.data);
});
})();
}, []);
How do I convert this:
const res =
{
"0": {
"id": "1",
"countryInfo": [
{
"_id": "4",
"lat": "33"
}
]
},
"1": {
"id": "2",
"countryInfo": [
{
"_id": "8",
"lat": "41"
}
]
}
}
into this json object:
const b =
{
"popup": {
"countryInfo": [
{
"_id": "1",
"lat": "33"
},
{
"_id": "2",
"lat": "41"
}
]
}
}
menuitemyou'll havecountryInfo, check my answer below and let me know if it works for you.