Heres a picture of what the browser console says when I do console.log(portfolio) where portfolio is the array. As you can see, it says the array is full of zeros but then also contains other numbers that aren't 0 in the same indices.
Picture of Array Values(https://i.stack.imgur.com/hWr68.png)
If I do portfolio[i] for any i between 0 and 29, I get 0. I want to get the other number such as 1257.72 for portfolio[0]. Thanks.
Here's the code:
let portfolioValue = []
useEffect(() => {
for (let i = 0; i < 30; i++) {
portfolioValue[i] = 0;
}
stocks.forEach(stock => {
const fetchData = async () => {
const response = await fetch(`https://api.twelvedata.com/time_series?symbol=${stock.ticker}&interval=1day&output=10&apikey=${key}`)
const data = await response.json()
for (let i = 0; i < 30; i++) {
portfolioValue[i] += (data.values[i].close * stock.numShares)
}
}
fetchData()
})
console.log(portfolioValue);
}, [user])