How can i use a string as a object name?
var a = "hello",
b = {
hello : "word"
};
alert(b.a);
This give my a in empty box. I want to still use the variable a.
How can ia string use as a objectname in javascript?
This is how you do it.
window["obj"] = { hello:"word"};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.