Arrays and Objects in JS 4/4 Reviewing Arrays


#1

var languages = ["HTML", "CSS", "JavaScript", "Python", "Ruby"];
var i = 0
for(i = 0; i <= (languages.length - 1); i++) {
console.log(languages[i]);
}

Can someone explain this in depth.
I only partly understand it.


#2

The definition of an Array can be found
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
The definition of a FOR-loop can be found
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for

Taking your code and expanding it a bit
maybe it becomes clearer...

var languages = ["HTML", "CSS", "JavaScript", "Python", "Ruby"];
console.log( languages);
console.log("languages has " + languages.length + " elements");
console.log("But remember the FIRST-element is expressed as languages[0]");
console.log("The FIRST element of languages is languages[0]: " + languages[0]);

var i = 0; // this is a so-called statement,
           // and should END with a semi-colon-;
           // it is also NOT needed !!

//In your [initialization] Always use the VAR keyword !!
for(var i = 0; i < languages.length ; i++) {
   console.log(languages[i]);
}