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";
}
ifclause the OP wants to use an equality operator either==or===. Also as with the above code, since the OP within theifclause assigns a value to a constant, the OP should get anTypeError: Assignment to constant variable.