473,394 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to print object attributes/values

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
Jul 16 '08 #1
5 3981
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
Jul 16 '08 #2
laredotornado wrote:
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
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Jul 16 '08 #3
On Jul 16, 4:57*pm, laredotornado <laredotorn...@zipmail.comwrote:
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.
Jul 16 '08 #4
Jorge wrote:
On Jul 16, 4:57 pm, laredotornado <laredotorn...@zipmail.comwrote:
>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
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Jul 16 '08 #5
laredotornado <la***********@zipmail.comwrites:
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/
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jul 16 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Krzysztof Stachlewski | last post by:
I tried to run the following piece of code: Python 2.3.4 (#53, May 25 2004, 21:17:02) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> o = object() >>> o.a...
18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
23
by: stewart.midwinter | last post by:
No doubt I've overlooked something obvious, but here goes: Let's say I assign a value to a var, e.g.: myPlace = 'right here' myTime = 'right now' Now let's say I want to print out the two...
3
by: Adam Monsen | last post by:
The following code uses the % operator to print possibly unitialized data attributes: ------------------------8<------------------------ class J: name = '' value = '' def __str__(self): vals =...
7
by: Martin Robins | last post by:
I am currently looking to be able to read information from Active Directory into a data warehouse using a C# solution. I have been able to access the active directory, and I have been able to return...
23
by: digitalorganics | last post by:
How can an object replace itself using its own method? See the following code: class Mixin: def mixin(object, *classes): NewClass = type('Mixin', (object.__class__,) + classes, {}) newobj =...
3
by: AWasilenko | last post by:
I'm still in the process of learning python via a handful of books I bought. One book I am reading just introduced Base Class Methods. I found that I needed more understanding on this concept and...
11
by: Andrus | last post by:
I'm implementing entity object which should populate its properties from database when property is first referenced. In RDL reports I use object properties like MyObject.MyProperty MyObject...
2
dream party
by: dream party | last post by:
Inserting a Flash (SWF, FLV) file into HTML web page is already an old and familiar thing to all of us. It is a rather non-flexible thing that just to edit some options in the template. However, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.