-1

Recently I am facing problem with javascript sub object value assign. My sample code is

var user = {
        name: {
            fname: 'Apple'
        }
    };

console.log(user);
user.name.fname = 'Orange';
console.log(user);

So its console twice But, fname value always show Orange. But I want output will be Apple then Orange. How do i do that or actually what happened? Please Let me explain actually what going on.

  • possible duplicate of [JavaScript logging object with mutating state](http://stackoverflow.com/questions/4993144/javascript-logging-object-with-mutating-state) and [Is Chrome's JavaScript console lazy about evaluating arrays?](http://stackoverflow.com/questions/4057440/is-chromes-javascript-console-lazy-about-evaluating-arrays) – Matt Ball Jan 16 '14 at 06:29

2 Answers2

0

Try this code:

var user = {
        name: {
            fname: 'Apple'
        }
    };

console.log(user.name.fname);
user.name.fname = 'Orange';
console.log(user.name.fname);

Cheers.

TonyMtz
  • 46
  • 3
0

You can use console.dir(object) to print object

console.dir(user); 

Don't need to use console.log(user.name.f);

LogPi
  • 706
  • 6
  • 11