Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #10376 > unrolled thread
| Started by | "FAQ server" <javascript@dotinternet.be> |
|---|---|
| First post | 2012-01-19 00:00 +0000 |
| Last post | 2012-01-20 19:09 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.javascript
FAQ Topic - How do I access a property of an object using a string? (2012-01-19) "FAQ server" <javascript@dotinternet.be> - 2012-01-19 00:00 +0000
Re: FAQ Topic - How do I access a property of an object using a string? (2012-01-19) Dr J R Stockton <reply1203@merlyn.demon.co.uk> - 2012-01-20 19:09 +0000
| From | "FAQ server" <javascript@dotinternet.be> |
|---|---|
| Date | 2012-01-19 00:00 +0000 |
| Subject | FAQ Topic - How do I access a property of an object using a string? (2012-01-19) |
| Message-ID | <4f175d0a$0$283$14726298@news.sunsite.dk> |
----------------------------------------------------------------------- FAQ Topic - How do I access a property of an object using a string? ----------------------------------------------------------------------- There are two ways to access properties: dot notation and 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"]; <URL: http://jibbering.com/faq/notes/square-brackets/> 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.
[toc] | [next] | [standalone]
| From | Dr J R Stockton <reply1203@merlyn.demon.co.uk> |
|---|---|
| Date | 2012-01-20 19:09 +0000 |
| Message-ID | <YL0Z7zJxvbGPFwk2@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #10376 |
In comp.lang.javascript message <4f175d0a$0$283$14726298@news.sunsite.dk
>, Thu, 19 Jan 2012 00:00:03, FAQ server <javascript@dotinternet.be>
posted:
>FAQ Topic - How do I access a property of an object using
>a string?
One might add, it appears, that this can be used as a shorter way of
testing in a main file whether a variable has been defined in an include
file
if (window["Tom"])
is shorter than
if (typeof(Tom)!='undefined')
--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web