Objects are composite data types which are built from primitives and other objects. An object’s building blocks are commonly referred to as its "fields" or "properties" comprising of `key -> value` pairs. A nested object is basically a data structure where an object refers to other objects, i.e. an object's values is another object or another set of objects. Such nested structures can be accessed by consecutively applying dot notation or bracket notation.
Objects are composite data types which are built from primitives and other objects. An object’s building blocks are commonly referred to as its "fields" or "properties" comprising of key -> value
pairs.
A nested object is basically a data structure where an object refers to other objects, i.e. an object's values is another object or another set of objects.
A nested object structure can be accessed by chaining dot notations or bracket notations. For example, in the following, if we want to access the first a
property from nestedObject1
:
obj = {
a: "1",
nestedObject1: [{
a: "2",
}, {
a: "3",
}]
};
Using dot notation, we can access that property like this:
obj.nestedObject1[0].a
//will return the value "2" of the first property `a` from nestedObject1
Using bracket notation, we can access that property like this:
obj["nestedObject1"][0]["a"]
//will return the value "2" of the first property `a` from nestedObject1