DEV Community

loading...

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

nedyudombat profile image
Nedy Udombat Author

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 Author

You are welcome @camicode