I have a specific array structure and I need to remove elements that match a certain criteria. Here is the initial array:
const updatedUsersInfo = [
{
alias: 'ba',
userId: '0058V00000DYOqsQAH',
username: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d8bab998bcb6b9e8edf6bbb7b5">[email protected]</a>',
permissionSets: [
'X00e8V000000iE48QAE',
'SCBanquetAccess',
'SCViewOnlyPermission'
]
},
{
alias: 'cs',
userId: '0058V00000DYOqtQAH',
username: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="32514172565c5302071c515d5f">[email protected]</a>',
permissionSets: [ 'X00e8V000000iE45QAE', 'SCCorpAdmin', 'SEAdmin' ]
}
]
The goal is to remove elements from the permissionSets array that start with 'X00'. The updated array should look like this:
const updatedUsersInfo = [
{
alias: 'ba',
userId: '0058V00000DYOqsQAH',
username: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="086a69486c6669383d266b6765">[email protected]</a>',
permissionSets: [
'SCBanquetAccess',
'SCViewOnlyPermission'
]
},
{
alias: 'cs',
userId: '0058V00000DYOqtQAH',
username: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7f1c0c3f1b111e4f4a511c1012">[email protected]</a>',
permissionSets: [ 'SCCorpAdmin', 'SEAdmin' ]
}
]
I have attempted different methods to achieve this, but I keep encountering issues and getting 'undefined' as the result. Here are a couple of the approaches I tried:
let test = updatedUsersInfo.forEach((element => element['permissionSets'].filter((permissionSet) => !permissionSet.includes('X00'))));
let test2 = updatedUsersInfo.forEach(element => {
element['permissionSets'].filter((permissionSet) => {
return !permissionSet.includes('X00')
});
});
I also attempted to use the splice method, but encountered errors indicating that the array could not be spliced. As a developer primarily experienced in C#, TypeScript presents a new challenge, so any assistance or guidance would be greatly appreciated!