JS中怎么把字符转为变量名使用?

JavaScript026

JS中怎么把字符转为变量名使用?,第1张

[javascript]

var test='{ colkey: "col", colsinfo: "NameList" }'

var test='{ colkey: "col", colsinfo: "NameList" }'

2.把文本转化为对象

[javascript]

var test='{ colkey: "col", colsinfo: "NameList" }'

var obj2=eval("("+test+")")

alert(obj2.colsinfo)

var test='{ colkey: "col", colsinfo: "NameList" }'

var obj2=eval("("+test+")")

alert(obj2.colsinfo)

3.把文本转化为数组

[javascript]

var test='["colkey", "col", "colsinfo","NameList" ]'

var obj2=eval("("+test+")")

alert(obj2.length)

var str = "win"

eval("var " + str)

console.log(win)

eval(str+"=3")

console.info(win)