Base on the following string
for(var i=0;i<${MyVar}.length;i++){ alert(${MyVar}[i]); }
How can I remove the ${ at the beginning and end } in the end of string, so it can be used like this?
for(var i=0;i<MyVar.length;i++){ alert(MyVar[i]); }
I'm creating a component in my system to inject javascript code and execute, but i need to replace the system variables to javascript variable.
var script = document.createElement("script");
script.innerHTML = "var ... "; // variables
script.innerHTML += transformCode(code); // code injected
document.getElementsByTagName("head")[0].append(script);
I already did the part of creating the variables from an array of objects, something like that:
function variableTransform(variables){
var html = "";
for(var key in variables) {
html += "var "+key+" ='"+variables[key]+"';\n";
}
//alert(html);
return html;
}

replace(/\${|}/g, "")