Skip to content
Advertisement

loop through array issue

I am calling an API that returns an array, i am trying to loop through the array but console is saying that the lenght is 0, never seen anything like it before and can not find out what is the issue here:

JavaScript

getUserNFTs function, I just console logged the last forEach, it is loging it after it is logged on the component consuming it, it is very strange.

JavaScript

what am I not getting here? I feel very frustrated after couple of hours trying to find out

Advertisement

Answer

Your problem is you’re using forEach which is not waiting for results as you expected.

You should modify it to a usual for loop to get rid of async callback function in forEach.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement