Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!