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.
Thanks!
.lengthArray.prototype.length - JavaScript | MDN
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[1]); would print out ‘Paris’