Consider the following object:
const test = {
resources: {
gatewayApi: {
resourceUri: 'https://bla',
resourceScope: 'D',
},
msGraphProfile: {
resourceUri: 'https://foo',
resourceScope: ['A', 'B', 'C'],
},
msGraphMail: {
resourceUri: 'https://bar',
resourceScope: ['A'],
},
msGraphGroupMember: {
resourceUri: 'https://bob',
},
},
}
The goal is to achieve a single array containing only the unique values defined in resourceScope:
const result = ['A', 'B', 'C', 'D']
To get to the desired result I took these steps:
// first create a new array with key value pairs
const newArray = Object.entries(test.resources)
// return only those values that have the property `resourceScope`
const result = newArray.filter(([, val]) => {
if ('resourceScope' in val) { return val.resourceScope }
})
At this point I'm a bit stuck. I would need to combine all returned arrays and a single string ('A') into one clean array. I've tried looking for examples but I couldn't really figure it out.
Thank you for your help.