Suppose I have a few variables:
a = 1
b = 2
c = 3
d = 4
vars = ['a', 'b', 'c', 'd'] // Values of them stored in a list
Now, I have a for loop:
for (i = 0; i < vars.length; i ++){
console.log(vars[i]);
}
Here, the output would be a,b,c,d
but what I'm willing to get is 1,2,3,4
.
Note: The vars
list should remain the same. This is just an example of what I'm trying to do...
Any idea on how we could fetch the variable just by a string name (given that the string name is exactly the same as the variable name)?