By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,628 Members | 1,692 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,628 IT Pros & Developers. It's quick & easy.

How to read the attribute's name ?

P: n/a
BFG
Hello everybody.

How can I read the object's attribute's name ? I mean something like this:

x = new Object
x.myAttr = 5

and how to get the 'myAttr' string ?

Thank you for your help.
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a


BFG wrote:
How can I read the object's attribute's name ? I mean something like this:

x = new Object
x.myAttr = 5

and how to get the 'myAttr' string ?


myAttr is a property name, why do you need to get it if you write that
code above yourself, in that case you know about the property and its
name so I am not sure why you need code to find it.
Anyway, if you want to enumerate the property names of that object x you
have created you can use a for..in loop:
var x = new Object();
x.myAttr = 5;
for (var propertyName in x) {
alert(propertyName + ': ' + x[propertyName]);
}

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.