And I'll see that it's printing out name, that's the name of the property, and
the value, name of the property and the value, name property and the value.
Okay that's all great.
Now we know that in JavaScript arrays are just objects and
the indices are just property names.
So technically speaking I could use the same type of four loop
on my names2 array as well.
So let's go ahead and try that.
Let's actually comment this out for
a minute, so we don't have it crowd our console, make a little bit more room.
Okay. So now let's say, for name in names.
It sounds pretty good.
So we'll say console.log, and we'll say hi, hello, and we'll say names,
and we'll use a computed property notation name.
So every time through the loop
this name will be equal a different property of their rate.
So the first time it will be equal zero,
because that's a property name of the array.
The second time it will equal one and the third time it will be equal two.
So this should work.
Let's go ahead and save that.
And I messed up something here, names is not defined, of course not.
Names2, let's go ahead and save names2 here.
Let's save that again.
Names2 is still not defined, and that's because I didn't put names2 right here.
Okay. So now it will work.
So now it says hello Yaakov, hello John, and hello Joe.
But the problem with this for loop is that arrays are objects after all.
So for example, there's nothing wrong with me saying names2.greeting = "hi".
Let's say I want to save a specific greeting that I want to use.
So now if I use the same array.
We'll go ahead and copy that.
And say, afterwards, hi.
And now if I use the same array, and let's go ahead and comment that out for
a minute and save it, what I'm going to get is hello Yaakov,
hello John, hello Joe, hello hi.
Now the reason that is, is because the greeting became a property of
the array no different than a number zero, or number two, or number one, and so on.
Greeting becomes a property of the array, and this for
loop loops over the property names of the object.
And since again, arrays are just objects in JavaScript, this for
loop will loop over properties, even over properties that really have
nothing to do with the core data that we want to loop over.