How to print object attributes/values

L

laredotornado

Hi,

I have this alert statement

alert(myObj);

which when executed, alerts "[object Object]", or something similar.
Is there a way I can see a list of attributes and values instead or do
I have to write a custom method for my object?

Thanks, - Dave
 
E

Erwin Moller

laredotornado schreef:
Hi,

I have this alert statement

alert(myObj);

which when executed, alerts "[object Object]", or something similar.
Is there a way I can see a list of attributes and values instead or do
I have to write a custom method for my object?

Thanks, - Dave

Hi,

A rude approach is:

for (myKey in myObj){
alert ("myObj["+myKey +"] = "+myObj[myKey]);
}

(Not tested)

Regards,
Erwin Moller
 
T

Thomas 'PointedEars' Lahn

laredotornado said:
I have this alert statement

alert(myObj);

which when executed, alerts "[object Object]", or something similar.
Is there a way I can see a list of attributes and values instead or do
I have to write a custom method for my object?

There is a way to see a list of enumerable properties and their values, and
a custom method would generalize this.

<http://www.jibbering.com/faq/#FAQ2_3>


PointedEars
 
J

Jorge

Hi,

I have this alert statement

alert(myObj);

which when executed, alerts "[object Object]", or something similar.
Is there a way I can see a list of attributes and values instead or do
I have to write a custom method for my object?

Yes there is, in FireFox : alert(myObj.toSource());

javascript:alert({a:1,b:2}.toSource());

--Jorge.
 
T

Thomas 'PointedEars' Lahn

Jorge said:
I have this alert statement

alert(myObj);

which when executed, alerts "[object Object]", or something similar.
Is there a way I can see a list of attributes and values instead or do
I have to write a custom method for my object?

Yes there is, in FireFox : alert(myObj.toSource());

It is supported in all Gecko-based UAs because it is a JavaScript[tm]
feature. The Matrix got you!


PointedEars
 
J

Joost Diepenmaat

laredotornado said:
Hi,

I have this alert statement

alert(myObj);

which when executed, alerts "[object Object]", or something similar.
Is there a way I can see a list of attributes and values instead or do
I have to write a custom method for my object?

Thanks, - Dave

Aside from the already given answers, my preferred method when using
browser-based javascript, is to use firefox's firebug extension and
call console.debug(myObj);

That will show a show summary in firebug's console/log tab, which you
can click to browse through the object including its properties. Very
handy.

See http://getfirebug.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,142
Messages
2,570,818
Members
47,362
Latest member
eitamoro

Latest Threads

Top