There is something wrong over here , what is it :(?


#1

var friends={
bill :{
firstName:"Bill",
lastName : "Gates",
number : "5842154554",
address :['lebanon','beirut','burj-hammoud','maraach-street']
},
steve:{
firstName:"Steve",
lastName:"Gachak",
number : "458 784 565",
address: ['i','dnt know' , ' where the hell', 'he living']
},
};
var list = function (){
for(var key in friends){
console.log("bill");
console.log("steve");
}


#2

You could write just two strings as well:

console.log("bill");
console.log("steve");

But your objective is to make computer write the list of friends automatically:

var list = function(obj) {
  for(var prop in obj) {
    console.log(prop);
  }
};

The "for ... in" statement here iterates over all the properties of the object and logs their names to the console.

list(friends);

In our case, the object is "friends", and its properties are "bill" and "steve".