Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to get blank properties and it's id from array of object

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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}
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading