ganjan
ganjan

Reputation: 7576

Key in Javascript is undefined when it is clearly defined when I print out object in consol

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?

Upvotes: 0

Views: 780

Answers (1)

Mico
Mico

Reputation: 2009

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.

Upvotes: 1

Related Questions