Output isn't what I expected


#1

The output us this:

{ firstName: 'Steve',
  lastName: 'Smith',
  number: '987-654-3210',
  address: [ [ '333 New Ave.' ], [ 'New England,', 'USA', '63929' ] ] }

How do I get the address to be on different lines? And why does it show all the brackets and quotation marks? Shouldn't it look like this:

  firstName: Steve
  lastName: Smith
  number: 987-654-3210
  address:  333 New Ave.  'New England USA 63929

#2

Hi @dillon.16,

Please give exercise link and your full code. Thanks!


#3

ok it's in unit 6 lesson 8 https://www.codecademy.com/en/courses/javascript-beginner-en-3bmfN/0/8?curriculum_id=506324b3a7dffd00020bf661
here is my code

var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Jones",
        number: '123-456-8790',
        address: [['222 Old Road'], ['Old England', 'England', '98676']]
        },
    steve: {
        firstName: "Steve",
        lastName: "Smith",
        number: '987-654-3210',
        address: [['333 New Ave.'], ['New England,','USA', '63929']]
        }
};
var list = function(friends){
    for(var person in friends){
        console.log(person);
    }
};
var search = function(name){
    for(var find in friends){
        if(friends[find].firstName === name){
            console.log(friends[find]);
        }
    }
}
list(friends);
search("Steve");

#4

Hi @dillon.16,

Because you are logging the entire object all at once into the console - in this line -

console.log(friends[find]);

you will only get the output as an object, like that:

{ firstName: 'Steve',
  lastName: 'Smith',
  number: '987-654-3210',
  address: [ [ '333 New Ave.' ], [ 'New England,', 'USA', '63929' ] ] }

With those braces and the quotation marks, it looks exactly the way you would assigned it to some variable

If you want it to be nicely formatted, you will need to log individual properties separately, like:

console.log(); // TODO log: firstName
console.log(); // TODO log: lastName
console.log(); // TODO log: number
console.log(); // TODO log: address

Hope that helps! :smiley:


#5

Thank you! That makes sense.