0

So I have an object that looks like this:

console

Clearly it contains two keys "200001" and "201601".

But when I try to access those two variables I get undefined!

Code bellow:

        console.warn($rootScope.layout);
        console.log('layout 200001', $rootScope.layout[200001]);
        console.log('layout 201601', $rootScope.layout[201601]);

Am I missing something?

ganjan
  • 7,356
  • 24
  • 82
  • 133
  • 3
    This is probably a quirk of Chrome's console. The first console message might show a later status of the object. See http://stackoverflow.com/questions/4057440/is-chromes-javascript-console-lazy-about-evaluating-arrays. You can confirm by doing `console.warn(JSON.stringify($rootScope.layout))` to force printing the current status of the object. – JJJ Jan 09 '17 at 09:17
  • 1
    Possible duplicate of [Is Chrome's JavaScript console lazy about evaluating arrays?](http://stackoverflow.com/questions/4057440/is-chromes-javascript-console-lazy-about-evaluating-arrays) – hindmost Jan 09 '17 at 09:31
  • console.warn(JSON.stringify($rootScope.layout)) shows {} !! Thanks! – ganjan Jan 09 '17 at 09:50

1 Answers1

1

Where are you calling this code and where do they get defined?

I think they get defined later than the console.log is called. When you click/expand the $rootScope variable in the chrome console, Chrome re-evaluates the variable then you can see them.

Mico
  • 1,978
  • 2
  • 13
  • 17