Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FAQ Topic - How do I access a property of an object using a string? (2009-12-09)

0 views
Skip to first unread message

FAQ server

unread,
Dec 8, 2009, 7:00:02 PM12/8/09
to
-----------------------------------------------------------------------
FAQ Topic - How do I access a property of an object using
a string?
-----------------------------------------------------------------------

There are two ways to access properties: the dot notation and
the square bracket notation. What you are looking for is the square
bracket notation in which the dot, and the identifier to its right,
are replaced with a set of square brackets containing a string. The
value of the string matches the identifier. For example:-

//dot notation
var bodyElement = document.body;

//square bracket notation, using an expression
var bodyElement = document["bo"+"dy"];

http://jibbering.com/faq/faq_notes/square_brackets.html


The complete comp.lang.javascript FAQ is at
http://jibbering.com/faq/

--

The sendings of these daily posts are proficiently hosted
by http://www.pair.com.

0 new messages