Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

value as variable name

Status
Not open for further replies.

KryptoS

Programmer
Feb 7, 2001
240
BE
Hello,

is it possible to use/convert a value in a variable to a variable name?

I have a object data.monday = 5

var test = "monday";

I want to use something like alert(data.test); Offcourse this is not working, anyone an idea what I could do?

visit my website at
 
aaaaaaaaaaaaaaaaaaaaaaaaah ... so easy... thanks

anyway, just for the record... is it possible in javascript to use a value as a variable?

visit my website at
 
Hi

KryptoS said:
is it possible in javascript to use a value as a variable?
Could you explain this ?

Anyway, the closest would be to use [tt]eval()[/tt] :
Code:
a='b'

c='a'

alert(c) [gray]// gives 'a'[/gray]

alert(eval(c)) [gray]// gives 'b'[/gray]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top