so i was trying to make custom variables generator but i couldn't figure out the way to create custom variavle with name from string it keeps sending error: Uncaught SyntaxError: Unexpected token '['
can someone help my code look like this:
var tempi = "csv"
var window[tempi]={0:"r"};
and i expect it to do
var csv ={0:"r"}
and create with this multiple variables with diffrent names
The error is that you are using the var initializer word for window, but window is already defined when program loads, so just avoid it:
var tempi = "csv"
window[tempi] = {
0: "r"
};
console.log(csv)
Your code looking good. It seems that you dont define window['csv'] previously. Take a look on this example:
tempi = 'csv'
data = [];
data['csv'] = {0: 'hello'};
console.log(data[tempi])