For Loops: Vacation Spots 3/8


#1

https://www.codecademy.com/courses/learn-javascript-loops/lessons/loops/exercises/for-loop?action=lesson_resume&course_redirect=introduction-to-javascript



let vacationSpots = ['Scotland', 'Namibia', 'Australia'];

for (let vacationSpotIndex = 0; vacationSpotIndex < vacationSpots.length; vacationSpotIndex++) {
  console.log('I would love to visit ' + vacationSpots[vacationSpotIndex]);
}


So I’m not having much trouble understanding ‘for’ loops so far. My questions is around how vacationSpotIndex picks up the strings from vacationSpots. I can’t see how console.log(… + vacationSpots[vacationSpotsIndex]) allows the index to use the strings from vacationSpots…

Does entering ‘vacationSpots[vacationSpotIndex]’ into console.log tie the index to the array?

Thanks


#2
array[index] =>  element value

As we can see, the loop does not see the strings. They are accessed by their index.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.