Matty
Matty

Reputation: 1981

An Inaccessible JavaScript Object property - Why is Firebug showing this?

So, I'm attempting to access the content of an object and for the life of me can't figure out why I can't. I'm starting to believe that the object doesn't have the properties that Firebug indicates that it does. More likely than that I'm just not using the right syntax to access them.

Give the following function:

function(userData) {
    console.log(userData);   // statement 1
    console.log(userData.t_nodecontent); // statement 2
}

Which generates the following FireBug output for statement 1

image

and undefined for statement 2. (Note: Originally incorrectly indicated that I was seeing unknown)

Is there something obvious that I'm overlooking in the way I'm attempting to reference the value of t_nodecontent? I'm at a loss :(

Upvotes: 3

Views: 603

Answers (3)

Mallee
Mallee

Reputation: 11

The problem, you'll find, is that userData is actually [userData]! Try accessing userData[0]. I've been caught like this before (most recently today with an object property of a Dojo.Data item)... if the object is passed in an array, Firebug displays the first element of the array, rather than the array itself.

Upvotes: 1

Sean Kinsey
Sean Kinsey

Reputation: 38046

unknown means that its a Host Object, like the ones provided by ActiveXObject in IE.

If there had been no such property, you would have seen undefined

So you are accessing its property, it's just has a type not defined by ECMAScript.

Upvotes: 2

blow
blow

Reputation: 13209

Try this and write output:

for(var key in userData){
   console.log(key, userData[key]);
}

Upvotes: 1

Related Questions