I have got array of nested array of objects . I want to get only Permission objects from data and I need to convert data array to permission objects .
"data":[
{
"Book":[
{
"label":"Can View",
"value":"can_view"
},
{
"label":"Can Create",
"value":"can_create"
},
]
},
{
"Articles":[
{
"label":"Can View",
"value":"can_view"
},
]
},
{
"Journals":[
{
"label":"Can Upload",
"value":"can_upload"
},
{
"label":"Can Download",
"value":"can_download"
}
]
},
{
"Permission":[
{
"label":"Can View",
"value":"can_view"
},
{
"label":"Can Create",
"value":"can_create"
}
]
}
]
I am trying to get permission objects from list of my data objects. I am using filter method for geting Permission array and want to convert permission objects, but I got nested arrays . where is the problem?
let dataPer = data.permissions.filter(item=>item.Permission).map(item=>item.Permission)
console.log(dataPer)
My accepted output would be :
let output= {
Permission:{
can_view:"can_view",
can_create:"can_create"
}
}