[英]Object property (type = object) is undefined despite existing in chrome console tree view
我已经将json响应保存为chrome控制台中的全局对象变量(chrome存储为temp1 ),将其对象属性设置为下面的fieldsObj1:
>> var fieldsObj1 = temp1.fields;
在chrome控制台中,此命令将显示fieldsObj1属性的树状视图,我在下面对其进行了扩展和粘贴,并保留了相关的“未定义”属性: contentAll.full 。
>> fieldsObj1
Object {contentText.split: Array[12], metricsListed: Array[1], sourceDescription: Array[1], sourceCode: Array[1], geoLocation: Array[1]…}
_rev: Array[1]
coded.matchedIn: Array[3]
[...这里跳过了许多按字母顺序排列的属性] ...直到我们到达以下相关的contentAll.full
contentAll.full: Array[1]
0: "Just updated my blog. Check it out! In Spite of Threats, Parents, States and Teachers are Dumping Common Core http://t.co/wlxofg2G2K #tcot"
length: 1
__proto__: Array[0]
[... Chrome控制台对象树中列出的更多属性...]
contentAll.full在镶边树对象查看器中显示为“ Array [1]”,其中数组项是我要存储到局部变量的文本数据。
但是,以下命令指示由于包含的对象fieldsObj1.contentAll未定义, 因此无法访问数组项。
fieldsObj1.contentAll.full[0]
TypeError: Cannot read property 'full' of undefined
fieldsObj1.contentAll.full
TypeError: Cannot read property 'full' of undefined
fieldsObj1.contentAll
undefined
当我在Chrome树形视图中看到它时,它是如何未定义的?
如何将看似不可访问的数据保存到局部变量中?
fieldsObj1.contentAll.full[0]
与...不同
fieldsObj1['contentAll.full'][0]
使用方括号符号可以更自由地定义对象键。 如您所见,在fieldsObj1
上有一个名为“ contentAll.full”的属性,但是定义该属性并不等同于创建fieldsObj1.contentAll
对象并在那里定义一个full
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.