Clearing up Array positions


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-NhsaT/2/3?curriculum_id=506324b3a7dffd00020bf661#
It's Section 11 in "Introduction For Loops" Lesson


When discussing cities.length, they say the array looks like :

var arrayName [1, 2, 3]

but we learned earlier that the positions are:

var arrayName [0, 1, 2]

Are they simply stating that when giving the .length, that's how the computer will count the data?


Replace this line with your code.


#2

Of course, when we talk about array length we mean how many elements are there. When we talk about postion we mean index (iterator) which always starts in 0. By the index we can access to the element of array:

var arr = [1, 5 , 3]; // 3 elements - it's array length
arr[0] = 1; // index 0 has value 1 
arr[1] = 5; // index 1 has value 5
arr[2] = 3; // index 2 has value 3

#3

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