Hey there, I'm facing a challenge with creating a new object based on the response from the backend.
This is the response that was returned to me:
acl:[
{
"user_type":5,
"user_id":"c7e5cb45ba764ad7ad29b5bdd4f12128",
"user_name":"John",
"view":true,
"modify":false,
"remove":false,
"modify_acl":false
},
{
"user_type":5,
"user_id":"f673beac0245462f8c71066536049e72",
"user_name":"Allan",
"view":true,
"modify":true,
"remove":true,
"modify_acl":false
}]
The task at hand is to filter out the properties with false values from the response and create a new array holding the access control values (acl). The desired new object should look like this:
[
{
"userType":5,
"label":"c7e5cb45ba764ad7ad29b5bdd4f12128",
"value":"John",
"acl":[
{"value":"view", "label":"View"}
]
},
{
"userType":5,
"label":"f673beac0245462f8c71066536049e72",
"value":"Allan",
"acl":[
{"value":"view", "label":"View"},
{"value":"modify", "label":"Modify"},
{"value":"remove", "label":"Remove"}
]
}
]
Currently, I am using the reduce method to eliminate all false values. However, I am struggling to generate the desired outcome.