0

I would like to know if it's possible to assign the name from a string variable as a variable name.

I want to accomplish something like this:

var names = array('var1', 'var2');
var eval(names[0]) = 28;

.... and in my JavaScript be able to manage such variables as var1.

Apalabrados
  • 1,098
  • 8
  • 21
  • 38
  • Why wouldn't you store the objects in the array? The eval() function evaluates or executes an argument. You wouldn't need to use eval at all to assign the first index of names to be 28. You realize here are you changing the value of the first index from a string 'var1' to an integer 28? – Radmation Jan 13 '17 at 23:31
  • I agree use objects - or you may look into structs although I do not think javascript has structs? I forget what they are called structs are a type of 'blah'...its getting late and I have been programming all day xD.. ANyways you can create your own TYPES through OBJECTS sort of. But ya point is use objects and you can define your own data structure.. – Radmation Jan 13 '17 at 23:34

0 Answers0