This is the JSON for user data.
result = {
"id": 5529,
"roles": [
{
"id": 10,
"name": "ADMIN",
"privileges": [
{
"id": 100,
"name": "ADD",
"systemId": 3
},
{
"id": 115,
"name": "DEL",
"systemId": 3
}
]
}
]
}
Have to check the given privilege value exist in the List and return true or false.
Tried few codes but not working as expected, one such code tried is given below. Here privilege = DEL, then it should return true.
result.roles.forEach((element:any) => {
element.privileges.filter(function(item:any){
if(item.name === privilege)
return true;
else
return false;
});
How can I check arrays inside an array efficiently and filter based on a value and return the result.
if(item.name === privilege) return true; else return false; });you can write justreturn item.name === privilege;