What am I missing, why is "jackpots" empty in the fixData function?
let jackpots = [];
let networks = [];
let games = [];
async function getJackpots() {
if(browser) {
const res = await fetch(`/api/jackpots/5`);
const res2 = await fetch('/api/networks');
const res3 = await fetch('/api/games');
return {
jackpots: res.ok && (await res.json()),
networks: res2.ok && (await res2.json()),
games: res3.ok && (await res3.json())
}
}
}
async function fixData(jackpots, network, games) {
jackpots.forEach((element) => {
console.log(element)
})
return jackpots;
}
let getData = getJackpots().then((result) => {
return result;
}).then((result) => {
let fix = fixData(result?.jackpots, result?.networks, result?.games)
});
Error:
/src/lib/components/Jackpot/index.svelte:24
jackpots.forEach(element => {
^
TypeError: Cannot read properties of undefined (reading ‘forEach’)
at fixData (/src/lib/components/Jackpot/index.svelte:24:11)
at eval (/src/lib/components/Jackpot/index.svelte:53:13)
>Solution :
What dataType is jackpots? method forEach() only can be apply to arrays and this case probably jackpots isn’t array when your value is undefined