Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
144
rated 0 times [  150] [ 6]  / answers: 1 / hits: 16055  / 15 Years ago, thu, september 17, 2009, 12:00:00

This way I could have a function that says whatever_way_you_do_this = something. Is this possible? Basically I could tell a function which variable I want to set by giving it a string that holds the name of the variable.



Thanks


More From » javascript

 Answers
16

Given:



var x = {
myproperty: 'my value'
};


You can access the value by:



var value = x['myproperty'];


If you're looking for a global variable, then you would check its container (window);



var value = window['x']['myproperty'];

[#98668] Tuesday, September 15, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devlin

Total Points: 474
Total Questions: 113
Total Answers: 100

Location: Sweden
Member since Fri, Apr 16, 2021
3 Years ago
;