I want to use a string as a variable name. But do not know how to do this. There are maybe many others way like map
. But I want to know the similar way like this:
var ibrahim = 100
console.log(window['ibrahim'])
output: 100
In JavaScript, if we declare a variable with var
then it will store in the global scope. For that, we can access that variable through the windows
object.
This method only works for var
.
I want to know if is there any similar way to do this with const
and let
?