[英]How to access the properties(another object) of an object?
I'm new to JS and I don't know how to access properties of an object, which are objects themselves. 我是JS的新手,我不知道如何访问对象本身的属性。 I have the following object(let´s call it ' a '), where I want to access -kk7b9q6FWN1VkCCflEX .name for example.
我有以下对象(我们称其为“ a ”),例如,我想在其中访问-kk7b9q6FWN1VkCCflEX .name。
I tried 我试过了
console.log(a.-kk7b9q6FWN1VkCCflEX.name)
but it gave me an error, due to '-' being an exception. 但这给了我一个错误,因为'-'是一个例外。 I know how to get the key names:
我知道如何获取密钥名称:
Object.keys(a)
but I cant figure out how to access their properties. 但我不知道如何访问它们的属性。
Could someone help me out? 有人可以帮我吗? Actually, I would be fine if someone could give me a "keyword" I can google on for this topic(because I don't even know what to google).
实际上,如果有人可以给我一个“关键字”,我可以在这个主题上用谷歌搜索(因为我什至不知道要搜索什么),我也可以。 Googling 'Accessing objects inside objects' didn´t help me :(
谷歌搜索“访问对象内部的对象”并没有帮助我:(
The keyword you're looking for is property accessor . 您要查找的关键字是property accessor 。
Object access in JavaScript can be done via .property
or ['property']
. JavaScript中的对象访问可以通过
.property
或['property']
。
In your case, ['-kk7b9q6FWN1VkCCflEX']
will work due to syntactic limitations in using the .
在您的情况下,由于使用时的语法限制,
['-kk7b9q6FWN1VkCCflEX']
可以使用.
where the property name has to be a valid identifier . 属性名必须是有效的标识符 。
The particular problem for -kk7b9q6FWN1VkCCflEX
is the -
sign. -kk7b9q6FWN1VkCCflEX
的特殊问题是-
号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.