What does this in statement mean?


#1

var list = function(obj) {
for(var hey in obj) { <-------
console.log(hey);
}
};

what does in mean on line 3?


#2

hey will get assigned each property of obj, then you can print the properties of obj

hey is defined in the loop, so you can name this anything you like.

just like you can access object values by property you can do:

obj[hey]

to get all values of obj

for in loop does so much work for you


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.