Some doubts in 6. contact list


the original code is at bottom, and i have two questions
1." if (friends[keys].firstName === name ){
return friends[keys];
"friends[keys].firstName" is the same as "friends.keys.firstName"? but when i use "friends.keys.firstName", the code can't run normally.

2 the outcome on the screen is that:

{ firstName: 'Steve',
lastName: 'Jobs',
number: '(408) 555-5555',
address: [ '1 Infinite Loop', 'Cupertino', 'CA', '95014' ] }
{"firstName":"Steve","lastName":"Jobs","number":"(408) 555-5555","address":["1 Infinite Loop","Cupertino","CA","95014"]}

my question is that , why "{"firstName":"Steve","lastName":"Jobs","number":"(408) 555-5555","address":["1 Infinite Loop","Cupertino","CA","95014"]}" will be shown repeatedly.

thanks a lot!

var friends = {};
friends.bill = {
  firstName: "Bill",
  lastName: "Gates",
  number: "(206) 555-5555",
  address: ['One Microsoft Way','Redmond','WA','98052']
friends.steve = {
  firstName: "Steve",
  lastName: "Jobs",
  number: "(408) 555-5555",
  address: ['1 Infinite Loop','Cupertino','CA','95014']

var list = function(obj) {
  for(var prop in obj) {

var search = function(name) {
  for(var prop in friends) {
    if(friends[prop].firstName === name) {
      return friends[prop];


the reason why this doesn't work, is because (thanks to your for in loop), keys contains a string. the dot notation only works for property name, not a string of property name.

the exercise calls the function(s) for validation purpose, if you want to see the true output go to jsbin, open the javascript and console tab, and press run in the top right corner


actually my code is as following:
// var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ["One Microsoft Way","Redmond","WA","98052"]
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(206) 555-6666",
address: ["One Apple Way", "Whitemond", "WA", "98052"]

var list = function (object) {
for (var property in object) {
console.log (property);

var search = function (name) {
for (var keys in friends) {
if (friends[keys].firstName === name ){
return friends[keys];
search("Steve"); //

keys are bill and steve. they are strings, but i think any keys are strings like "name" "age" and so on.
so you mean""is a string. and the dot notation can only be followed by a single name, no another dot notation..??
but the meaning of friends.key.firstName and friends[keys].firstName is the same?
sry, i am a newbie. thanks for you help


in Js bin, the outcome is as following:
[object Object] {
address: ["One Apple Way", "Whitemond", "WA", "98052"],
firstName: "Steve",
lastName: "Jobs",
number: "(206) 555-6666"

and the output is empty.

i dont understand why it shows "[object Object] " and the different order of address and number.

actually i can't figure out what is calling the function(s) for validation purpose. so sometimes the exercise doesn't show the true output?


ignoring the loop for a second, there are two ways you can access objects:


either using object notation (first) or associative array notation (second)

because the for in loop stores the values in keys as string, you are used to use the associative array notation (the square brackets)

output is for html/css code, you are working in console. Ignore/close the output tab

The default conversion from an object to string is "[object Object]", which is why you see object object. (remember, for in loop stores the results as string)

the exercise needs to validate your code works correctly, to achieve this, function calls are made behind the scene, but this function calls do result in output in your console window


thank you very much for so many helps.
i have another doubt in I have to celebrate you baby.
do i need to create a topic?


wait, i should have added:

keys = "bill"

to the example

Yes, preferable make a new topic. I could a have been able to clarify something


i want to check again , the meaning of friends[keys].name is the same as the only difference is that the latter form is not correct?
actually, in the later exercises, i use the form like, then there is no problem,.


keys contains a string (thanks to your for in loop), so then you can't the dot notation

code from earlier exercises aren't re validated, does it pass the exercise or actually work?


oh. so name is not string, it is the key/property, then can use dot notation.

it pass the exercise and somehow works but not actually works. problem is about another aspect which i have already post.


yes, very good :slight_smile:

still something that requires explanation?

if you want to get more in depth, read this article


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