Working example with global var:
var example_var = 'global var example'; var x = function(){ var var_name = 'example_var'; alert('Global var value is: ' + window[var_name]); }
How can I do same thing with a local variable? Like this (not working example):
var x = function(){ var example_var = 'Local var example'; var var_name = 'example_var'; alert('Local var value is: ' + window[var_name]); }
If you have no other way, you can try eval
it
var x = function(){
var example_var = 'Local var example';
var var_name = 'example_var';
alert('Local var value is: ' + eval(var_name));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With