From The Blog

Javascript: have variable variables

26 November 2013, in

In PHP to have "Variable" variables.

For example

$x = "variable";

$$x = "hello, world!";

echo $variable;" //"hello, world!"

So as a workaround you can do as the following:

var obj = {}
obj.foo = 42;

var bar = 'foo';
console.log(obj[bar]);


Post a Comment