I'm new to JS and I don't know how to access properties of an object, which are objects themselves. I have the following object(let´s call it ' a '), where I want to access -kk7b9q6FWN1VkCCflEX .name for example.
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 .
Object access in JavaScript can be done via .property
or ['property']
.
In your case, ['-kk7b9q6FWN1VkCCflEX']
will work due to syntactic limitations in using the .
where the property name has to be a valid identifier .
The particular problem for -kk7b9q6FWN1VkCCflEX
is the -
sign.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.