Using variables as variables

F

Frank

Hey Everyone,

Lets say I have a variable declared as such:

var newVariable="opener";

How can I then use this variable to access the opener of 'window' ?

Meaning, I dont want to access it as such:

window.opener

but as: window.+newVariable

So it uses the contents of newVariable to access the opener.

I need this because I have a couple of variables which I need to
concat to eachother as a string,
and this string in turn is the variable I need to access from
window.opener.varSomething
where varSomething is the variable that stores the variable I need to
access.

Hope I am clear enough,
Regards Frank
 
M

Martin Honnen

Frank said:
Lets say I have a variable declared as such:

var newVariable="opener";

How can I then use this variable to access the opener of 'window' ?

Meaning, I dont want to access it as such:

window.opener

but as: window.+newVariable

Use the bracket notation object[expression] e.g.
window[newVariable]
 
L

Lee

Frank said:
Meaning, I dont want to access it as such:

window.opener

but as: window.+newVariable

window[newVariable]

In addition to the "dot" notation (and other methods) attributes
of objects are also available via "square bracket" notation, as
if the object were an array indexed by string attribute names.


--
 
F

Frank

Frank said:
Meaning, I dont want to access it as such:

but as: window.+newVariable

window[newVariable]

In addition to the "dot" notation (and other methods) attributes
of objects are also available via "square bracket" notation, as
if the object were an array indexed by string attribute names.

--


Thanks everyone, I did not know you can also access it using the
square bracket notation.
Regards,
Frank
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
Thanks everyone, I did not know you can also access it using the
square bracket notation.

Which proves that previous responses ought to have advised you to read
the newsgroup FAQ. See below.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top