DEV Community

Discussion on: Understanding Javascript Array Series IV - Array Loops & Iteration Part I

Collapse
 
camicode profile image
CamCode

Of course !! sorry but English it's not my first language, however I don't understand the final example. Can you explain me better why in both loops doesn't print "mixed"?
I hope it's clearer now :)

Thread Thread
 
nedyudombat profile image
Nedy Udombat

Okay great, in the first solution I used a for ... in loop with loops through the property name of an array. That array has the following property names 0, 1, 2, type.

The second solution I use for ... of which loops through the property values of an array, basically the elements of the array. 1, 2, "nedy";

If I want to print mixed which a property of the items array, I would have to do this console.log(items.type) // "mixed".

so for ... in deals with the property names, for ... of deals with the property values(elements of the array).

Thread Thread
 
camicode profile image
CamCode

Thanks for this explanation, now I understand better!

Thread Thread
 
nedyudombat profile image
Nedy Udombat

You are welcome @camicode