I have trouble when wont to forEach my array object from api, when i run the forEach the console not show anything my code and my array object is like this:
function renderingData(){
const ra = fetching()
console.log(typeof(ra))
console.log(ra)
ra.forEach( as => console.log(as))
}
renderingData()
Totals 224 object in array, and my forEach nor working,
and this is my fetching function :
function fetching() {
let result = []
fetch("the-url", {
"method": "GET",
"headers": {
"x-rapidapi-host": "the-host",
"x-rapidapi-key": "the-key"
}
})
.then(res => res.json())
.then(res => res.response.forEach( d => {
let ar = {
negara:d.country,
positif:d.cases.active,
sembuh:d.cases.recovered,
meninggal:d.deaths.total,
total:d.cases.total
}
result.push(ar)
}))
return result
}
but when i try to test writting maual the array like this :
function renderingData(){
// const ra = fetching()
const rr = [{negara: "China", positif: 723, sembuh: 77474, meninggal: 4633, total: 82830},
{negara: "Italy", positif: 105813, sembuh: 66624, meninggal: 26977, total: 199414},
{negara: "Spain", positif: 85069, sembuh: 120832, meninggal: 23521, total: 229422},
{negara: "Germany", positif: 37839, sembuh: 114500, meninggal: 6050, total: 158389}
]
console.log(typeof(rr))
console.log(rr)
rr.forEach( as => console.log(as))
}
renderingData()
all is normal and forEach working to, how to fix this please ?