A multi-level json object, delete the object is an empty key value, think you can use recursion, how to achieve

let arrn=[
        {
            "MENU_URL": "serviceManage",
            "MENU_ID": "8619ca0b6fbc42649a27475e339d5d4a",
            "MENU_INFO": [
                {
                    "MENU_URL": "userInfo",
                    "MENU_ID": "104a580029c54e139210b7e87dca6d89",
                    "MENU_INFO": [],
                    "MENU_NAME": ""
                }
            ],
            "MENU_NAME": ""
        },
        {
            "MENU_URL": "serviceManage/recordQuery",
            "MENU_ID": "d379e3f38cb3472ab18287034f32ef46",
            "MENU_INFO": [
                {
                    "MENU_URL": "dashboard",
                    "MENU_ID": "104a580029c54e139210b7e87dca6d89",
                    "MENU_INFO": [
                        {
                            "MENU_URL": "dashboard",
                            "MENU_ID": "104a580029c54e139210b7e87dca6d89",
                            "MENU_INFO": [],
                            "MENU_NAME": "222"
                        }
                    ],
                    "MENU_NAME": "111"
                },
                {
                    "MENU_URL": "dashboard",
                    "MENU_ID": "104a580029c54e139210b7e87dca6d89",
                    "MENU_INFO": [],
                    "MENU_NAME": "333"
                }
            ],
            "MENU_NAME": ""
        }
    ]
    let tmparr=arrn.map(function (value) {
        if (value.MENU_INFO.length===0){
            delete value.MENU_INFO
        }else{
            value.MENU_INFO.map(function (val) {
                if (val.MENU_INFO.length===0){
                    delete val.MENU_INFO
                }
            })
        }
        return value
    })
    console.log(tmparr)
MENU_IDkey
Mar.26,2021

separate the processing function

function exec(array) {
  array.forEach(item => {
    if (item.MENU_INFO.length === 0) {
      delete item.MENU_INFO
    } else {
      exec(item.MENU_INFO)
    }
  })
}

exec(arrn);

console.log(arrn)

if you are afraid to change the source data, you can cloneDeep it in advance and use map delete to change the source data

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e998fd-1768.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e998fd-1768.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?