I have an array which looks like this after I console.log
it:
[
{
Country: 'US',
CityName: 'Seattle',
Region: 'WA',
PostalCode: '99301',
StreetName: '3512 Alaska Street'
},
to_EmailAddress: { results: [ [Object] ] }
]
Funny thing is, the length of this array is 1, not 2. So, when I try console.log(arr[0])
, I get:
{
Country: 'US',
CityName: 'Seattle',
Region: 'WA',
PostalCode: '99301',
StreetName: '3512 Alaska Street'
}
When I try to console.log(arr[1])
I get undefined
.
How do I get the to_EmailAddress
attribute? Even better, how do I make to_EmailAddress: { results: [ [object] ] }
part of the 1st element in the array. Basically, I want:
[
{
Country: 'US',
CityName: 'Seattle',
Region: 'WA',
PostalCode: '99301',
StreetName: '3512 Alaska Street',
to_EmailAddress: { results: [ [Object] ] }
},
]
But I am not sure how to create that when I cannot even access to_EmailAddress
attribute
2
Answers
Whatever you console.log (maybe you should put that part here as well) is not the valid javascript array.
If you have array, each item has a value (i.e. reference to object or value of primitive type). You cant have "named variable" like
to_EmailAddress: { results: [ [Object] ] }
as part of the array.The valid array is for example if you have object that has this variable
{to_EmailAddress: { results: [ [Object] ] }}
Its a monkey patched property
to_EmailAddress
.Gives the output:
Just acces it like any other property: