【发布时间】:2018-03-11 18:52:16
【问题描述】:
我有一个具有各种属性的全局对象,其值为字符串。当用户在 HTML 输入中键入字符串时,我使用 javascript 将该字符串分配给变量。我需要将该字符串转换为属性名称并返回与该属性关联的字符串。
例如:
myglobalobject = {
propertyname : "String value to be returned."
}
function GetInput(){
mystring = document.getElementById('input').value;
myproperty = convertstringToProperty(str); //This is where I need a solution
return myglobalobject.myproperty;
}
【问题讨论】:
-
直接使用
myglobalobject[mystring]。你不需要转换任何东西。 -
myGlobalObj[str] -
面部护理。如果它是一条蛇,它会咬我的。
标签: javascript string object properties