Does anyone know how could I select a variable from a String in JavaScript? Here\'s what I\'m basically trying to achieve:
var myLang = \"ESP\"; var myText_
You can use eval for that but this is very bad practice:
eval
console.log(eval("myText_" + myLang);
I'll suggest to have an object instead:
var myLang = "ESP"; var texts = { 'ESP': "Hola a todos!", 'ENG': "Hello everyboy!" }; console.log( texts[ myLang ] );