6. List'em all: for/in loops


#1



https://www.codecademy.com/en/courses/javascript-beginner-en-3bmfN/0/6?curriculum_id=506324b3a7dffd00020bf661


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) {
            console.log(firstName);
        }
    };

list(friends);**


#2

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.


#3

have a look at this also


#4

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