如何使用包含属性名称的变量检查对象属性是否存在?

问题:

I am checking for the existence of an object property with a variable holding the property name in question. 我正在检查是否存在一个对象属性,其中包含一个保存有问题的属性名称的变量。 spa

var myObj;
myObj.prop = "exists";
var myProp = "p"+"r"+"o"+"p";

if(myObj.myProp){
    alert("yes, i have that property");
};

This is undefined because it's looking for myObj.myProp but I want it to check for myObj.prop 这是undefined由于它正在寻找myObj.myProp但我但愿它检查myObj.prop .net


解决方案:

参考一: https://stackoom.com/question/kK88/如何使用包含属性名称的变量检查对象属性是否存在
参考二: https://oldbug.net/q/kK88/How-to-check-if-object-property-exists-with-a-variable-holding-the-property-name
相关文章
相关标签/搜索