ler ler - 15 days ago 6
Javascript Question

Javascript make variable from an array of characters

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

Answer

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.

Comments