How to access array objects add person details
CodePudding user response:
const someArrayWithObjects = [
{
object: {
nestedObject: {
someKey: "hello"
}
}
}
];
const yourValue = someArrayWithObjects[0]['object']['nestedObject']['someKey']
console.log(yourValue)
CodePudding user response:
You can try using multiple bracket notations.
const array = [
{xyz:{
addperson:{
address:"hello"
}
}
]
const access = array[1]['addperson']['address']
CodePudding user response:
You can iterate over the array items using Array
methods, such as map
or forEach
.
If you want to directly read value of object property, then you can use dot notation
(.), like:
array?.[1]?.['-NE_OARSxk']?.addperson
On the line above array
is your array variable and I used ?.
- Optional chaining, because in your array you have some null
values, so Optional chaining helps not to go into errors, when you directly refer to the property values of Object
s s or elements of Array
s.