ler ler - 1 year ago 65
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 Source

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'")


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download