JavaScript

How is "list" in the for loop connecting to the length of the array playList?

In the for loop, the loop is running as long as i < list.length, but I don't understand how the list is connecting to the amount of items in the playList array. How did this function determine that there were 6 items in the array?

4 Answers

Thanks Chris! I was confused on how "list" was connected to the amount of items in the array "playList". But now i understand. "list" only receives a value once the function is called. At the very end the program the function is called like this:

printList(playList);

Since the array "playList" was passed in the function, the function runs and .length will count the amount of items in playList.

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 43,382 Points

For this video?

https://teamtreehouse.com/library/twodimensional-arrays

There the condition for the loop is i < songs.length where songs is passed in as a parameter.

If not could you provide a link?

Hi Kris,

Thanks for the response, its actually for this video: https://teamtreehouse.com/library/using-for-loops-with-arrays

chris robinson
chris robinson
2,648 Points

It determines that there were six items in the array by the length property, length will return all values so when the code is ran the program will see and identify all that are in the collection