How you can make a variable from an array of characters in Javascript.
chars = ["a","b","c","d"];
chars[1],chars[0],chars[2] = "Hellow world";
alert(bac); // Hellow world
How you can make a variable from an array of characters in Javascript.
chars = ["a","b","c","d"];
chars[1],chars[0],chars[2] = "Hellow world";
alert(bac); // Hellow world
There is no need for eval
or map
:
var chars = ["a", "b", "c", "d"];
window[chars[1] + chars[0] + chars[2]] = "Hellow world";
console.log(bac); // Hellow world
This is absolutely not a good practice. Only do it for fun. No professional work uses code like this.
That said:
chars = ['a', 'b', 'c']
eval("window." + chars.join('') + " = 'Hello World'")
alert(abc)
Yep.