Friday, 1 July 2022

Remove all empty array from array of object using lodash or omit-deep-lodash

  1. i have one array of object

  2. need to remove empty array KEYS from that, which is nested

  3. here is the sample of array of object

  4. need to remove every fieldGroup array which is empty, with nested level

  5. how can i remove that using LODASH or omit-deep-lodash or any third party library

    [
    {
        "id": "sch_CV8e5NzZXwXhNp3TGnpryEmub2EC",
        "display_name": "test name",
        "connection_profile": {
            "type": "NAVIGATION",
            "access_methods": [
                {
                    "submit": true,
                    "ui_web": [
                        {
                            "id": "dslogo",
                            "fieldGroup": [] // need to remove all fieldGroup array which is empty array
                        },
                        {
                            "key": "label",
                            "fieldGroup": []
                        },
                        {
                            "key": "forgotpassword",
                            "fieldGroup": [ // need which has length
                                {
                                    "id": "forgotpassword",
                                    "key": "forgotpassword",
                                    "type": "link",
                                    "className": "d-flex flex-grow-1 justify-content-end",
                                    "templateOptions": {
                                        "label": "Need help?",
                                        "className": "pull-right",
                                        "hideRequiredMarker": true
                                    },
                                    "_id": "62b4665e9bba345e1937f669"
                                }
                            ]
                        }
                    ],
                    "navigator_method": "login",
                    "_id": "62b4665e9bba345e1937f663"
                }
            ]
        }
    },
    {
        "id": "sch_CV8e5NzZXwXhNp3TGnpryEmub2ED",
        "display_name": "test name 2",
        "connection_profile": {
            "type": "NAVIGATION",
            "access_methods": [
                {
                    "submit": true,
                    "ui_web": [
                        {
                            "key": "forgotpassword",
                            "fieldGroup": [
                                {
                                    "id": "forgotpassword 11",
                                    "key": "forgotpassword 11",
                                    "type": "link 11"
                                },
                                {
                                    "id": "forgotpassword 22",
                                    "key": "forgotpassword 22",
                                    "type": "link",
                                    "className": "d-flex flex-grow-1 justify-content-end"
                                }
                            ]
                        },
                        {
                            "id": "dslogo",
                            "fieldGroup": []
                        },
                        {
                            "key": "label",
                            "fieldGroup": []
                        }
                    ],
                    "navigator_method": "login",
                    "_id": "62b4665e9bba345e1937f663"
                }
            ]
        }
    }
    

    ]

how can i remove nested level empty array using lodash?



from Remove all empty array from array of object using lodash or omit-deep-lodash

No comments:

Post a Comment