I got through the lesson but I do not understand what the reasoning is behind what I’m doing, it just seems random. Below are screenshots:
Can someone explain this like I’m five? I thought the .length was supposed to show how many characters were in a string. I also don’t think I completely understand the concept of iterators. I did what I’m supposed to by copying the lesson but I don’t know what I was doing.
Basicly what it does is, it returns the number of elements in the array.
For example in your screenshoot you have an array vacationSpots which has 3 elements inside, the
console.log(vacationSpots.length); would return 3.
each item in array is accessible with using the “index” of the element, so for example your array vacationSpots with 3 elements each has its own index.
first element in the vacationSpots has an index of 0
second element in the vacationSpots has an index of 1
and so on.
Index-es help us access the elements that are inside an array, for example if you wanted to print the second element you would use index of 1 to select it.
console.log(vacationSpots); would print out ‘Paris’
Thank you, that makes so much more sense. Something about the phrasing of that particular lesson was really throwing me off.