'Need to return more than 1 value from a recursive fuction in javascript. Needto return the data in the format mentioned

Code for reference. There is an issue for the value returned as removeKey, it is always getting a null value.

const clearEmpties = (obj: IParms) => {
        var removeKey: string[] = []
        for (var key in obj) {
            if (!obj[key] || typeof obj[key] !== "object") {
                continue
            }
            clearEmpties(obj[key]);
            if (Object.keys(obj[key]).length === 0) {
                removeKey.push(key)
                console.log("k", key, obj[key]);
                delete obj[key];
            }
        }
        return {obj , removeKey};
    }

Input for the code snippet is :

{"a" :{
"m": {
"m1": "cmp",
"m2": "M2M",
"m3": "2"
}
"p":{}
}
}

Output should be : 2 values , return an object by removing all empty objects & list the removed path.

{"a" :{
    "m": {
    "m1": "cmp",
    "m2": "M2M",
    "m3": "2"
    }   
    }
 }

& removeKey = a.p



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source