I'm attempting to access the roles array from this object but encountering the following error:
TypeError: Cannot read properties of undefined (reading 'forEach')
Here is the code snippet causing the issue:
this.data.roles.forEach(role => {
this.roleIds.push(role.id); // roleIds is a separate array of numbers that I've created.
})
The data object looks like this:
{
"userID": "abcd",
"firstName": "FNU",
"lastName": "LNU",
"allowedOffices": [
{
"roles":[
{
"id":"ABC",
"name": "Read"
},
{
"id":"XYZ",
"name": "Write"
}
]
}
]
}
this.data.roles.forEach(role => {
this.roleIds.push(role.id); // roleIds is another array of numbers I have defined.
})