Can someone help me to print out the required data on the web by parsing JSON array of objects? In the below example, I want to print Apple, Mango, Grapes.
Below are the codes:
JSON format
{
"data":{
"summary": {
'a1':13223,
'b1': 23
},
"regional": [
{
'aa1': "Apple",
'bb1': 456
},
{
'aa1': "Mango",
'bb1': 496
},
{
'aa1': "Grapes",
'bb1': 126
},
]
},
'lastdata': '2946'
}
fetchApi.js
url = 'apiUrl'
export const fetchData = async () => {
try {
const { data } = await (await fetch(url)).json();
const modifiedData = {
region: [...data.regional]
}
return modifiedData;
} catch (error) {
console.log(error)
}
}
tabular.js
import { fetchData } from "../api/fetchApi";
const Tabular = () => {
const [fetchedState, setFetchedState] = useState([])
useEffect(() => {
const fetchAPIState = async () => {
const dailyData = await fetchData()
setFetchedState(dailyData)
console.log(dailyData)
}
fetchAPIState()
}, [])
return (
<>
<h1>{}</h1>
</>
)
}
When I console.log(dailyData) the result is this:
"region": [
{
'aa1': "Apple",
'bb1': 456
},
{
'aa1': "Mango",
'bb1': 496
},
{
'aa1': "Grapes",
'bb1': 126
},
]
But I am unable to print Apple, Mango, Grapes in the h1 tag. It shows error. I tried using map method.