List em all


#1

Hi. this is my code:

var friends = {
bill:{
firstName: 'Bill',
lastName: 'Perez',
number: 658-1111,
address: ['Ciudad de la paz 2251']
},
steve:{
firstName:'Steve',
lastName:'Hernandez',
number: 777-2343,
address: ['Cabildo 22']
}
var list = function (name) {
for (var firstName in friends)
{ console.log (firstName);

    }
    }
};

It does ot work. can anybody help please? thank you.


#2

"friends" is an object that contains data.
"list" is a function that takes given data, manipulates it and returns the result.

This said, these 2 are separate beings. In your code "list" function is inside "friends", what may cause the problem.
Good luck.


#3

Thank you. it worked by doing it this way:

var friends = {
bill:{
firstName: 'Bill',
lastName: 'Perez',
number: 658-1111,
address: ['Ciudad de la paz 2251']
},
steve:{
firstName:'Steve',
lastName:'Hernandez',
number: 777-2343,
address: ['Cabildo 22']
}

};
var list = function (name)
{
    for (i in friends)
    {
        console.log (i)
    }}

now Im stuck in the next one hahah