Hey, In this bit of script, the products variable is set as an array and I was wondering what the "products.length" doing exactly? what is it calculating to get the length? for (var i = 0; i < products.length; i++) { document.write("<option>" + proucts[i].item); } Code (markup): I think this souds really confusing but basicaly I want to know where "products.length" is getting its answer from bearing in mind it is an array?
It's the 'length' of the array, the amount of indexes it has. And in the code they use the less than sign ("<") because then length property gives the number of indexes in the array, but don't forget an array starts from 0 to x.
Its a property of the array. As such, javascript tracks each time you modify the array. So if you add an element, it increments it. Etc. Close to magic.