6. List'em all: for/in loops



I have my list function doing what I want it to do but I still don't understand how I made the for/in loop work. I am confused with the difference between the key part and the parameters, and the "in" part of the for/in loop

Replace this line with your code. 
**var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "8932900923",
        address: ['One Microsoft Way', 'Redmond', 'WA', '98052']
    steve: {
        firstName: "Steve",
        lastName: "King",
        number: "666",
        address: ['164 Portacove', 'Picadilly St', 'Picadilly']

var list = function(Obj) {
        for(var firstName in Obj) {



here the list function has a param (Obj)
with list(friends) you call the function and give it an argument, which is the friends object. Defined on line 1.

The for...in statement iterates over the enumerable properties of an object, in arbitrary order. For each distinct property, statements can be executed.

var firstname can be named anything, it's the key behind which lies the value.

It is very hard for me to explain. Can you be more specific about what confuses you.


have a look at this also


Thanks for the help. I understand it better :slight_smile: