I have an array:
var arr = ['a', 'b', 'c'];
I need to declare within a for loop, variables value_x- when x is each one of the array value.
what I've tried:
var i;
for(i=0;i<3;i++){
var x = 'hello there';
var str = 'var ' + `value_${arr[i]}` + ' = ' + "'" + x + "'" + ';'
eval(str);
}
now, str =
var value_a = 'hello there';
but the eval() call return this error:
error: EvalError: Dynamic code evaluation disallowed
now, I saw also solution which used window object, like:
window[`value_${arr[i]}`] = x;
and this also return error:
error: ReferenceError: window is not defined
which because this is local script, not on the server. please help.