What is the purpose of the [i] in the for loop

What is the purpose of the [i] in the for loop
0

#1

I have some line of code that I don’t fully understand. I am looking through objects in an api and was wondering what is the purpose of the [i] in d2.follows[i].user.display_name if the code is:

$.getJSON(followerURL, function(d2){
  for(var i=0; i<d2.follows.length; i++){
    var displayName = d2.follows[i].user.display_name;
 following.push(displayName);

I’m searching through object to find the number of followers a channel has. is Here is an image of the object I would greatly appreciate an explanation of this block of code.


#2

d2.follows is an array, so represents the index a particular element in the array. This code has a for loop which will iterate through the d2.follows array and first assign the user.display_name of that particular element to the variable displayName and finally push displayName into another array called following.


#3

follows is an array so we use a for-loop to iterate through its elements. i is the index of each element and we use it to get its value.


#4

It’s an operator that returns the i’th element of the array.

Example
a = [x, y, z]
a[0] returns x
a[1] returns y
and so on