Skip to content
Advertisement

.push() is not working outside of the for loop

I have already handled a response from an API call. I then export the data into a function that i’m using a for loop inside. The const diomerda is passed to the ejs file where i am outputting the array data from the API. However the data in the array is over 5000 entries, so i want to run a for loop to populate the ejs file with the entire array. But when I use loop.push it does not populate the const loop. console.log(loop) just reads [].

Once the const loop = [] is populated with the array i was then going to pass the data into the const diomerda = [json.entries[loop].character.name]

I’f anyone has any other ideas on how to acheive what i’m trying to do then please feel free to send away. Thanks in advance.

JavaScript

Advertisement

Answer

Once the const loop = [] is populated with the array i was then going to pass the data into the const diomerda = [json.entries[loop].character.name]

If what you want is to populate diomerda with each character name return from the api, do this

JavaScript

OR in simpler terms

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