Like, I've a condition like this:
var a="avar", b=3;
var a+b="some value";
// expecting to make, avar3="some value";
Is it possible somehow? Or any alternative way?
Like, I've a condition like this:
var a="avar", b=3;
var a+b="some value";
// expecting to make, avar3="some value";
Is it possible somehow? Or any alternative way?
You can do:
var a="avar", b=3;
window[a+b]="some value";
This will declare a global variable avar3
with value "some value"
This:
function ns() { return this; }
var a="avar", b=3;
ns()[a+b] = "some value";
alert(avar3);
will create variable with the name "avar3" in current namespace.
No Doesn't work like that.
i dont know if this if what you're trying to do but:
var c=a+b; c="some value";
you can use object properties for something like this
var obj = { a: 'avar', b:'3'};
obj[obj.a+obj.b]='some value';
console.log(obj.avar3); //the output is 'some value'