I want to make a variable dynamically. Example-
var a ="pres"+b;
where b is a variable, and then use a
as a different variable.
I want to make a variable dynamically. Example-
var a ="pres"+b;
where b is a variable, and then use a
as a different variable.
You'll be in a much confortable solution using an object to store values, and the bracket notation :
var store = {};
var theEnd = 'Something';
store['b'+ theEnd] = 10 ;
store['c'+ theEnd] = 20 ;
You can easily iterate in existing keys and values with :
for (var key in store) {
var value = store[key];
console.log(' store has key:' + key + ' having value ' + value);
}
// output :
// store has key bSomething having value 10
// store has key cSomething having value 20
u have to use eval() to do this... but dont be eval! this is not a good style!
Your question is a no logical; Is normal that a and b are variables|||
You have to use new String("string");
and in your case
var a = new String("pres")+b ;
but you can use simplier var a ="pres"+b;