471,316 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Referencing an object property dynamically

If I create a number of objects, obj0, obj1, obj2,... and they each have
a property assigned (so I could reference, say, obj0.foo) how can I
reference it when it is dynamically built? For example, with

var tmp = 0;

the following all fail:

myFunction( obj+tmp.foo );
myFunction( "obj"+tmp.foo );
myFunction( ["obj"+tmp].foo );
myFunction( ["obj"+tmp]foo );

var k = "obj"+tmp;
myFunction( k.foo );

var k = ["obj"+tmp];
myFunction( k.foo );
Andrew Poulos
Jul 23 '05 #1
1 1384
On Thu, 23 Dec 2004 12:40:50 +1100, Andrew Poulos <ap*****@hotmail.com>
wrote:
If I create a number of objects, obj0, obj1, obj2,... and they each have
a property assigned (so I could reference, say, obj0.foo) how can I
reference it when it is dynamically built?


[snip]

This is covered in the FAQ notes
(<URL:http://www.jibbering.com/faq/faq_notes/faq_notes.html>) article
regarding bracket notation.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by DC Gringo | last post: by
10 posts views Thread by Macka | last post: by
17 posts views Thread by Paul Helmuth | last post: by
7 posts views Thread by msdev | last post: by
2 posts views Thread by HankD | last post: by
reply views Thread by rosydwin | last post: by

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.