'Accessing Hierarchy Data in an Object Javascript
I need to access the id value in a Javascript object to display a simple message that the user has membership if the id value equals a specific value.
I'm getting Uncaught Type Error not defined 'id' message
In the console it's displayed as
subscriptions: Array(1)
0: // COMMENT Don't know what this is
autoRenew: false
canRenew: false
expiryDate: "2022-10-26T00:00:00"
membership:
id: "819AGBHDRLQHNHPHKKMPKLGPMDRDTDMVL"
I'm assuming equivalent JSON is something like:
subscriptions {
0
{
membership: {
id: "819AGBHDRLQHNHPHKKMPKLGPMDRDTDMVL"
}
}
}
My Javascript Code
const userObj3 = userObj['subscriptions']['0']['membership']['id'];
if (userObj3 = "819AGBHDRLQHNHPHKKMPKLGPMDRDTDMVL") {
greeting = "You have membership";
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
