Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
80
rated 0 times [  87] [ 7]  / answers: 1 / hits: 18981  / 15 Years ago, thu, may 28, 2009, 12:00:00

How can i concatenate var names to declare new vars in javascript?:



var foo = 'var';
var bar = 'Name';


How can i declare variable varName?


More From » javascript

 Answers
196

Try something like:



window[foo + bar] = whatever; 
alert(varName);


do not use the eval function unless you are absolutely certain about what's going in. window[] is much safer if all you're doing is variable access


[#99443] Friday, May 22, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
naomim

Total Points: 344
Total Questions: 95
Total Answers: 114

Location: Wales
Member since Mon, May 17, 2021
3 Years ago
;