I used jsonData[‘some content][‘some content]
when using javascript. It seems to be different from the general array,
but I don’t know what it means and how to use it.
what is its name?
For exmple
const Data = {
'apple':{
'banana':{
//....
}
}
}
I tried googling but I can’t figure it out because I don’t even know how to describe it haha
3
Answers
They are property accessors, its a way to access data in an object literal or JSON using the key, for object literals you can also use the dot operator a an accessor.
The main structure is an object. Objects are a list with keys where you can access a specific value with a specific key. You are making an object inside an object inside an object, so
Data["apple"]
will return{"banana": {/*whatever you have in here*/}}
. The[value]
is an object assessor.Example:
The notation
jsonData['someKey']['anotherKey']
looks like array access but is actually for accessing nested properties within objects, not array elements. This is object notation, not array notation, used to retrieve values from objects based on keys. Each key in the notation represents a level in the nested object structure.Accessing Nested Object Properties
There are two primary ways to access properties of an object:
Dot Notation:
object.property
Bracket Notation:
object['property']
Here is an example: