6. List 'em all - double names


#1


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


the code shows:
yael
tidhar
yael
tidhar

what am i doing wrong? :frowning:

var friends = {
   yael: {
     firstName: "Yael",
     lastName: "Smith",
     number: "054123456",
     address: ["bla", "nes tsiona", "5"]
     },
   tidhar: {
    firstName: "Tidhar",
    lastName: "Dough",
    number: "0542349258",
    address: ["bla bla", "road", "4"]
    }
};

var list = function (friends) {
    for (var yael in friends) {
    console.log(yael);
    } for (var tidhar in friends) {
    console.log(tidhar);
    }
};


#2

ok i changed the function part to this:
var list = function (friends) {
for (var friends in friends) {
console.log(friends);
}
};

and now it works. but why doesnt it also work with the original code i wrote?


#3

From MDN

var obj = {a: 1, b: 2, c: 3};
    
for (var prop in obj) {
  console.log('obj.' + prop, '=', obj[prop]);
}

// Output:
// "obj.a = 1"
// "obj.b = 2"
// "obj.c = 3"

With yael and tidhar you gave your properties only different names.

Read more about for ... in here


#4

hello I am the oneeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee


#5

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