0

Usually, in javascript, I use [""] to convert a string into a variable:

 ["variable_name"] = variable_value;
// same as variable_name = variable_value

And to be clear I've used window["variable_name"] = varialbe_value. IE just dont' understand the [""] part.

eval() can work but I've been told not to use eval() (cause it's dangerous). So is there any other option?

NewBieBR
  • 344
  • 1
  • 5
  • 16
  • Curious, why would you want to do that? – Script47 Sep 07 '17 at 08:13
  • In this case for a project, I want to do: Tweenmax.to(abc, def, {width: 10}). That "width" is a variable, it's can be any other css property and I get it as a string. I use {[prop]: prop_value} -> this works on any browser except IE – NewBieBR Sep 07 '17 at 08:17
  • This is not a duplicate... IE just doesn't understand the ["variable_name"] part. Nothing change with window["variable_name"] or whatever – NewBieBR Sep 07 '17 at 08:24
  • 1
    Please check the other answers within the linked question. – Script47 Sep 07 '17 at 08:25

0 Answers0