Confused about how the code logs the correct answer (15.10 - List all the properties)


#1

For this question, I used the below code which works and I understand.

var a = "fullName";
var b = "mayor";
var c = "population";
var d = "borough";

var m = [a, b, c, d];

for (var m in nyc) {
console.log(nyc[m])
};

I was playing around to see how else I could get to the answer and put the below code in and it does log what is necessary for me to move on but I don't understand why. Can someone help explain this to me?

for (var s in nyc) {
console.log(nyc[s])
};


#2

the variable in the for loop can be called anything...

for (var x in nyc) {
statement or statements;
};

When you call this, all your telling the 'for' loop is, for every property of an object, do this. But your using it here for an array, which is not recommend...

x is set to 0 and loops over as many times as it's needed to loop though all properties.