4. Iterating over an arrays


#1

https://www.codecademy.com/en/courses/javascript-beginner-en-9Sgpi/0/4?curriculum_id=506324b3a7dffd00020bf661

Could you please explain to me, why I can't do this in the way stated below? I know the correct answer, this is just the first idea I've came up with and I still cannot understand why it is not working.


var languages = ["HTML", "CSS", "JavaScript", "Python", "Ruby"];

for (languages.length = 0; languages.length <=4; languages.length += 1)
{
    console.log(languages[languages.length]);
}


#2

because you set the length of languages to zero? In essence making the array empty:

var languages = ["HTML", "CSS", "JavaScript", "Python", "Ruby"];
languages.length = 0
console.log(languages)

#3

Thank you kindly. It now seems obvious...


#4