user1234 user1234 - 2 months ago 6
JSON Question

Returns undefined on a object prop even though it exsits-JS

I'm having the same issue as mentioned here: Can't access object property, even though it exists. Returns undefined

However in my case it's a property with

data.hostId.id
, where
data
comes in as full object and
hostId
is shown undefined when its actually present in the json object, here's how it looks:

enter image description here

enter image description here

As you can see, I'm trying to access the
qgUSerHost
(at the very end) from the object and it throws undefined. I tried
setTimeout
, not working…

I also tried the solution mentioned in that post but nothing helped.
Any ideas on this one?

Answer

I think you should access that property like this.hostAsset["qgUserHost.id"] because of the . in the property name, so it wouldn't try to access the property id from some qgUserHost object.

Comments