Need help with my for loop (Twitch API project)

Need help with my for loop (Twitch API project)
0.0 0

#1

I’m trying to make it so a for loop will iterate through an array of channels (each with two links) and will push the appropriate data to my html in the appropriate place.
The ‘appropriate place’ is the tricky part.

I intended to use the current run of the for loop (i) as a string (var apiNum = i.toString) in order to push each piece of data to a specific area, through $(#“name”+apiNum). However, it appears to be pushing a random selection of intended data all to the top row (name0).

Could somebody explain to me why this is wrong and how I could do it better please? all help is much appreciated and here is the link to the full project… feel free to laugh at how not good it currently is :sweat_smile:


Twitch API Ajax call
#2

use let instead of var
let apiNum = i.toString();

Read this to understand why this works: https://hacks.mozilla.org/2015/07/es6-in-depth-let-and-const/


#3

Oh wow I was so much closer than I thought I was, thank you Elise, thank you as well for posting info as to why it works. Super helpful :smiley: Cannot express enough thanks!