Advertisements
i want to get empty properties(only need to check role,group and subgroup) and it’s id both in array of objects.
let tempdata = [
{
"id": 41,
"tool": "Artifactory",
"role": "",
"group": "Dish",
"subgroup": "Ehub test 009",
"subscriptionId": "artifactory-ehub-test-009"
},
{
"id": 4,
"tool": "Gitlab",
"role": "Owner",
"group": "IDP",
"subgroup": "IDP-Service-Templates",
"subscriptionId": "gitlab-51663585"
}
]
What i tried so far is this:
tempdata.filter(item=>item.group=='' || item.subgroup=='' || item.role=='').map(item=>item.id)
but this only gives my id [41] what i want is [{"id":41,"blank_properties":["role"]}]
Can somebody please help.
>Solution :
you can simply do it this way
tempdata.map((item)=>{
let d = [];
if(item.role === ''){
d.push('role')
}
if(item.group ===''){
d.push('group')
}
if(item.subgroup===''){
d.push('subgroup')
}
return {...item,'blank_prop':d}
})